Ernesto García García <[EMAIL PROTECTED]> writes:
> >>[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.

Use xrange instead of range.  If you want to do it with no variables,
hmmm:

  from itertools import islice, starmap, repeat
  import random

  possible_notes = range(12)
  length = 9

  print list(islice(starmap(random.choice, repeat((possible_notes,))), length))


>>> ## working on region in file /usr/tmp/python-21885hGZ...
[10, 0, 6, 7, 8, 1, 9, 6, 11]

Maybe you're sorry you asked ;)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to