[Newbie] List from a generator function

Ernesto García García titogarcia_nospamplease_ at gmail.com
Sun Jul 23 04:47:42 EDT 2006


>>I'm sure there is a better way to do this:
>>
>>[random.choice(possible_notes) for x in range(length)]

> There is at least a better way to ask the question.  The subject has
> nothing to do with the body of your post.  Or am I missing something?

Sorry, I should have explained better. I just want to build a fix length 
list made up of elements generated by a function, in this case 
random.choice(). I don't like my list comprehension, because I'm using 
that dumb variable x and the range() list.

Ernesto



More information about the Python-list mailing list