transforming list
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Oct 24 09:28:43 EDT 2007
sandipm wrote:
> hi james,
> this is one implementation using python dictionaries.
>
> report ={}
> for row in data:
> if not row[0] in report:
I'd use:
if row[0] not in report:
> report[row[0]] = [row[0], row[1], 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0]
> if row[2]:
> report[row[0]][row[2]+1] = row[3]
> reports = report.values()
or even:
report ={}
for code, team, game, bet in data:
if code not in report:
report[code] = [code, team, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]
else:
assert report[code][1] == team
if game:
report[code][game + 1] = bet
reports = report.values()
-Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list