andrea crotti <andrea.crott...@gmail.com> writes: > It's very weird though this sharing and still doesn't really look > rightl, is it done just for performance reasons?
It could consume unbounded amounts of memory otherwise. E.g. if there are millions of items in the group. If you're not worried about that situation it's simplest to just convert each group to a list for processing it: for k,g in groupby(...): gs = list(g) # do stuff with gs calling list(g) reads all the elements in the group, advancing groupby's internal iterator to the next group. Since you've copied out all the group elements, you don't have to worry about the sharing effect. -- http://mail.python.org/mailman/listinfo/python-list