Hi,
I ran into a bit of an unexpected issue here with itertools, and I
need to say that I discovered itertools only recently, so maybe my way
of approaching the problem is not what I want to do.
Anyway, the problem is the following:
I have a list of dictionaries, something like
[ { a: 1, b: 1,
Nico Schlömer wrote:
I ran into a bit of an unexpected issue here with itertools, and I
need to say that I discovered itertools only recently, so maybe my way
of approaching the problem is not what I want to do.
Anyway, the problem is the following:
I have a list of dictionaries, something
On 4 May, 11:10, Nico Schlömer nico.schloe...@gmail.com wrote:
Hi,
I ran into a bit of an unexpected issue here with itertools, and I
need to say that I discovered itertools only recently, so maybe my way
of approaching the problem is not what I want to do.
Anyway, the problem is the
Does this example help at all?
Thanks, that clarified things a lot!
To make it easier, let's just look at 'a' and 'b':
my_list.sort( key=itemgetter('a','b','c') )
for a, a_iter in groupby(my_list, itemgetter('a')):
print 'New A', a
for b, b_iter in groupby(a_iter, itemgetter('b')):
I'd try to avoid copying the list and instead just iterate over it:
def iterate_by_key(l, key):
for d in l:
try:
yield l[key]
except:
continue
Hm, that won't work for me b/c I don't know all the keys beforehand. I
could
On 4 May, 12:36, Nico Schlömer nico.schloe...@gmail.com wrote:
Does this example help at all?
Thanks, that clarified things a lot!
To make it easier, let's just look at 'a' and 'b':
my_list.sort( key=itemgetter('a','b','c') )
for a, a_iter in groupby(my_list, itemgetter('a')):
Nico Schlömer wrote:
So when I go like
for item in list:
item[1].sort()
I actually modify *list*? I didn't realize that; I thought it'd just
be a copy of it.
No, I misunderstood your code there. Modifying the objects inside the list
is fine, but I don't thing you do that, provided
Are you basically after this, then?
for a, a_iter in groupby(my_list, itemgetter('a')):
print 'New A', a
for b, b_iter in groupby(a_iter, itemgetter('b')):
b_list = list(b_iter)
for p in ['first', 'second']:
for b_data in b_list:
#whatever...
Nico Schlömer wrote:
Hi,
I ran into a bit of an unexpected issue here with itertools, and I
need to say that I discovered itertools only recently, so maybe my way
of approaching the problem is not what I want to do.
Anyway, the problem is the following:
I have a list of dictionaries,
status: open
title: itertools: problem with nested groupby, list()
versions: Python 2.6
Added file: http://bugs.python.org/file17198/iterator-test.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8609
Mark Dickinson dicki...@gmail.com added the comment:
You'd be better off asking this on the python mailing list
http://mail.python.org/mailman/listinfo/python-list (or in some other forum);
this tracker is for reporting bugs in Python itself, not bugs in code written
in Python.
[The problem
Nico nico.schloe...@gmail.com added the comment:
Okay, thanks for the hint.
Closing as invalid.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8609
___
12 matches
Mail list logo