however, he did bring up a python-idea worthy general topic:
Sometimes you want to iterate without doing anything with the results of the iteration.
So the obvious is his example -- iterate N times:
for i in range(N):
do_something
but you may need to look into the code (probably more than one line) to see if i is used for anything.
I know there was talk way back about making integers iterable, so you could do:
for i in 32:
do something.
which would be slightly cleaner, but still has an extra i in there, and this was soundly rejected anyway (for good reason). IN fact, Python's "for" is not really about iterating N times, it's about iteraton over a sequence of objects. Ans I for one find:
for _ in range(N):
To be just fine -- really very little noise or performance overhead or anything else.
However, I've found myself wanting a "make nothing comprehension". For some reason, I find myself frequently following a pattern where I want to call the same method on all the objects in a sequence:
for obj in a_sequence:
obj.a_method()
but I like the compactness of comprehensions, so I do:
[obj.a_method() for obj in a_sequence]
but then this creates a list of the result from that method call. Which I don't want, so I don't assign the results to anything, and it just goes away.
But somehow it bugs me that I'm creating this (maybe big) ol' list full of junk, just to have it deleted.
Anyone else think this is a use-case worth supporting better? Or should I jstu get over it -- it's really not that expensive to create a list, after all.
-Chris