Steve,
> Why don't you just pass a slice to itemgetter?
py> for key, bereich in groupby(eingabe, itemgetter(slice(0, 2))):
WHOW, that is great! that makes it really simple, just have to structure
the SQL to make a real "cut first, serve first" structure.
Thanks to all who helped!
also the "f
Harald Massa wrote:
def getdoublekey(row):
return row[0:2]
for key, bereich in groupby(eingabe,getdoublekey):
print "Area:",key
for data in bereich:
print "--data--", data[2:]
Why don't you just pass a slice to itemgetter?
py> eingabe=[
... ("Stuttgart","70197","Fernsehturm","20
Harald Massa wrote:
> def getdoublekey(row):
> return row[0:2]
>
> for key, bereich in groupby(eingabe,getdoublekey):
> print "Area:",key
> for data in bereich:
> print "--data--", data[2:]
>
> which indeed leeds to the expected result, while looking less "hacky" ..
> on the
> 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
Old, very old informatical problem: I want to "print" grouped data with
head information, that is:
eingabe=[
("Stuttgart","70197","Fernsehturm","20"),
("Stuttgart","70197","Brotmuseum","123"),
("Stuttgart","70197","Porsche","123123"),
("Leipzig","01491","Messe","91822"),
("Leipzig","01491","Scha