Re: Common Python Idioms

2006-12-07 Thread Danny Colligan
> 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

Re: Yield

2006-11-16 Thread Danny Colligan
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

Re: Yield

2006-11-16 Thread Danny Colligan
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

Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Danny Colligan
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

Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Danny Colligan
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