Message391494
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. |
|
Date |
User |
Action |
Args |
2021-04-21 07:02:32 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, alvarezdqal |
2021-04-21 07:02:32 | serhiy.storchaka | set | messageid: <1618988552.79.0.81373854185.issue43899@roundup.psfhosted.org> |
2021-04-21 07:02:32 | serhiy.storchaka | link | issue43899 messages |
2021-04-21 07:02:32 | serhiy.storchaka | create | |
|