while expression feature proposal

Ian Kelly ian.g.kelly at gmail.com
Wed Oct 24 19:39:16 EDT 2012


On Wed, Oct 24, 2012 at 5:08 PM, Paul Rubin <no.email at 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)



More information about the Python-list mailing list