Good use for itertools.dropwhile and itertools.takewhile

Alexander Blinne news at blinne.net
Tue Dec 4 19:48:06 CET 2012


Am 04.12.2012 19:28, schrieb DJC:
>>>> (i for i,v in enumerate(w) if v.upper() != v).next()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'generator' object has no attribute 'next'

Yeah, i saw this problem right after i sent the posting. It now is
supposed to read like this

>>> def split_product(p):
...     w = p.split(" ")
...     j = next(i for i,v in enumerate(w) if v.upper() != v)
...     return " ".join(w[:j]), " ".join(w[j:])

Greetings



More information about the Python-list mailing list