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 diction
> 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:
>#what
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, provi
On 4 May, 12:36, Nico Schlömer 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')):
> > print 'New A', a
> 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
coul
> 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'
On 4 May, 11:10, 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
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, som
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"