Good use for itertools.dropwhile and itertools.takewhile

Alexander Blinne news at blinne.net
Tue Dec 4 18:18:01 CET 2012


Another neat solution with a little help from

http://stackoverflow.com/questions/1701211/python-return-the-index-of-the-first-element-of-a-list-which-makes-a-passed-fun

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

Greetings



More information about the Python-list mailing list