T
Thorsten Kampe
What is the best way to find out the length of an iterator? len()
doesn't work. In the above code snippet[1] I am only interested in the
index (= length of the iterator), so I'm using len(list(iterator))...
Anything better?
Thanks, Thorsten
[2]
def part(seq, func):
from itertools import takewhile
index = len(list(takewhile(func, seq)))
return [seq[:index], seq[index:]]
doesn't work. In the above code snippet[1] I am only interested in the
index (= length of the iterator), so I'm using len(list(iterator))...
Anything better?
Thanks, Thorsten
[2]
def part(seq, func):
from itertools import takewhile
index = len(list(takewhile(func, seq)))
return [seq[:index], seq[index:]]