Search a sequence for its minimum and stop as soon as the lowest possible value is found

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Sat Jan 7 01:55:54 EST 2017


Paul Rubin writes:

> Peter Otten writes:
>> How would you implement stopmin()?
>
> Use itertools.takewhile

How? It consumes the crucial stop element:

   it = iter('what?')
   list(takewhile(str.isalpha, it)) # ==> ['w', 'h', 'a', 't']
   next(it, 42) # ==> 42



More information about the Python-list mailing list