> Is there a list somewhere listing those not-so-obvious-idioms?
I don't know about lists of not-so-obvious idioms, but here's some
gotchas (there may be some overlap with what you're asking about):
http://zephyrfalcon.org/labs/python_pitfalls.html
http://www.ferg.org/projects/python_gotchas.html
j>> x = primes(11)
>>> x.next()
2
>>> x.next()
3
>>> x.next()
5
>>> x.next()
7
>>> x.next()
11
>>> x.next()
Traceback (most recent call last):
File "", line 1, in ?
StopIteration
>>>
Danny Colligan
On Nov 16, 10:4
Now that we're on the subject, what are the advantages of using
generators over, say, list comprehensions or for loops? It seems to me
that virtually all (I won't say everything) the examples I've seen can
be done just as easily without using generators. For example,
Fredrik's initial example in
I see. Thanks for the helpful response.
Danny
Duncan Booth wrote:
> "Danny Colligan" <[EMAIL PROTECTED]> wrote:
>
> > In the following code snippet, I attempt to assign 10 to every index in
> > the list a and fail because when I try to assign number to 10, nu
In the following code snippet, I attempt to assign 10 to every index in
the list a and fail because when I try to assign number to 10, number
is a deep copy of the ith index (is this statement correct?).
>>> a = [1,2,3,4,5]
>>> for number in a:
... number = 10
...
>>> a
[1, 2, 3, 4, 5]
So, I