On Wed, Oct 24, 2012 at 5:08 PM, Paul Rubin <no.email@nospam.invalid> wrote:
> from itertools import dropwhile
>
> j = dropwhile(lambda j: j in selected,
>                  iter(lambda: int(random() * n), object()))
>              .next()
>
> kind of ugly, makes me wish for a few more itertools primitives, but I
> think it expresses reasonably directly what you are trying to do.

Nice, although a bit opaque.  I think I prefer it as a generator expression:

j = next(j for j in iter(partial(randrange, n), None) if j not in selected)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to