while expression feature proposal

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Thu Oct 25 16:49:16 EDT 2012


Am 25.10.2012 18:36 schrieb Ian Kelly:
> On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel
> <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de>
> wrote:
>>> j = next(j for j in iter(partial(randrange, n), None) if j not in
>>> selected)
>>
>>
>> This generator never ends. If it meets a non-matching value, it just skips
>> it and goes on.
>
> next() only returns one value.  After it is returned, the generator is
> discarded, whether it has ended or not.  If there were no valid values
> for randrange to select, then it would descend into an infinite loop.
> But then, so would the dropwhile and the original while loop.

You are completely right. My solution was right as well, but didn't 
match the problem...

Yours does indeed return one random value which is guaranteed not to be 
in selected.

Mine returns random values until the value is not in selected. I just 
misread the intention behind the while loop...


Thomas



More information about the Python-list mailing list