Serhiy Storchaka <[email protected]> added the comment:
The drawback of that recipe of partition() is that it calls predicate twice on
every element. The following implementation calls it only once for every
element:
def partition(pred, iterable):
t1, t2 = tee((bool(pred(x)), x) for x in iterable)
return (x for p, x in t1 if not p), (x for p, x in t1 if p)
but it may be less efficient for fast predicates.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43899>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com