I'd write it like this:
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
for week, (times_full, times_not_full) in bi
Steven Bethard wrote:
...
> Using a two element list to store a pair of counts has
> a bad code smell to me.
...
Why is that? It strikes me as the cleanest way to solve that problem,
as long as it's easy enough to figure out what each element really
represents. You could name each element, bu
Double clicking python.exe will give you the command line version. To
run IDLE, click Start -> Programs -> Python 2.x -> IDLE.
pythonw.exe is useful for running GUI scripts. In Windows there are two
types of programs: command line and gui programs. python.exe is the
command line version. Su
ou can say:
bin_item = bin.setdefault(x, [0, 0])
bin_item[0] += 1
That should be equivalent. My example with the class is similarly broken.
Adam
Adam Tomjack wrote:
> Randy,
>
> I'd probably use a two element list.
>
> Instead of using an if/else to check if
Randy,
I'd probably use a two element list.
Instead of using an if/else to check if an element is in your dict and
initialize it, you can use the setdefault() function. The docs for
dictionaries explain it pretty well.
bin = {}
for whatever:
for [a, b] in foo:
x
roblems. Is there something
simple I'm forgetting to do? I'm out of ideas. Does anybody have any
ideas about how to attack this problem?
Thanks,
Adam Tomjack
--
http://mail.python.org/mailman/listinfo/python-list