head for grouped data - looking for best practice

Diez B. Roggisch deetsNOSPAM at web.de
Sat Mar 12 08:39:41 EST 2005


> which indeed leeds to the expected result, while looking less "hacky" ..
> on the other hand side, that "getdoublekey" ist not very flexible; when
> doing the same with 3 Columns forming the head information, I have to
> define the next function...

Make getdoublekey something like this (untested):

def get_key(f=0,t=1):
     def _get_key(list_value):
          return list_value[f:t]
     return _get_key

Then use it like this:

for key, bereich in groupby(eingabe,get_key(t=key_size)):
    print "Area:",key
    for data in bereich:
        print "--data--", data[key_size:]

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list