itertools: problem with nested groupby, list()

2010-05-04 Thread Nico Schlömer
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,

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Ulrich Eckhardt
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

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Jon Clements
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

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Nico Schlömer
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')):

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Nico Schlömer
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

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Jon Clements
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')):    

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Ulrich Eckhardt
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

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Nico Schlömer
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...

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Peter Otten
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,

[issue8609] itertools: problem with nested groupby, list()

2010-05-04 Thread Nico
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

[issue8609] itertools: problem with nested groupby, list()

2010-05-04 Thread Mark Dickinson
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

[issue8609] itertools: problem with nested groupby, list()

2010-05-04 Thread Nico
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 ___