trictionary?
Randy Bush
randy at psg.com
Mon Aug 29 12:57:38 EDT 2005
> bin = {}
> for start, end, AS, full in heard:
> week = int((start-startDate)/aWeek)
> counters = bin.setdefault(week, [0, 0])
> if full:
> counters[0] += 1
> else:
> counters[1] += 1
yes! thanks!
> Using an idea you used earlier, you could get smaller code by saying:
> for start, end, AS, full in heard:
> week = int((start-startDate)/aWeek)
> counters = bin.setdefault(week, [0, 0])
> counters[not full] += 1
> Or
> for start, end, AS, full in heard:
> week = int((start-startDate)/aWeek)
> bin.setdefault(week, [0, 0])[not full] += 1
> Or even
> for start, end, AS, full in heard:
> bin.setdefault(int((start-startDate)/aWeek), [0, 0])[not full] += 1
as you say, too clever.
> Using lists to represent structs is perfectly fine if the list doesn't
> live longer than about one screen of code.
i can definitely see that. in last weeks installment, i buried a
complex trinary tree in a class.
thanks for the advice!
randy
More information about the Python-list
mailing list