?

Ruediger larudwer at freenet.de
Thu May 22 06:51:30 EDT 2008


Paul Hankin wrote:


> This is better written using takewhile...
> itertools.takewhile(lambda x: x != value, iterable)
> 
> But if you really need to reinvent the wheel, perhaps this is simpler?
> 
> def test(iterable, value, op=operator.ne):
>     for x in iterable:
>         if not op(x, value):
>             return
>         yield x


yes you are right it is. However as i mentioned in my post i came up with an
solution 'like' that. In fact my original code was to complex to post.
While simplifying it, i've overseen the obvious solution.

For special cases where you need to do more complex tests, the best solution
is IMHO to hide it in an generator function like above.






More information about the Python-list mailing list