Looping [was Re: Python and the need for speed]
MRAB
python at mrabarnett.plus.com
Mon Apr 17 21:37:29 EDT 2017
On 2017-04-18 02:09, Paul Rubin wrote:
> Ben Bacarisse <ben.usenet at bsb.me.uk> writes:
>> ? I get "AttributeError: 'itertools.dropwhile' object has no attribute
>> 'next'" from your example.
>
> Hmm, .next() worked ok for me in Python 2.7.5. Not sure what happened.
> Maybe something went wrong with my paste. Oh well.
>
>> Coming from the lazy language Haskell, I find your example natural...
>
> Yep ;)
>
Your mistake was that you didn't say it was Python 2. :-)
In Python 3 it's:
c = next(itertools.dropwhile(
lambda c: c==' ',
iter(lambda: sys.stdin.read(1),None)
))
More information about the Python-list
mailing list