This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients alvarezdqal, rhettinger, serhiy.storchaka
Date 2021-04-21.07:02:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618988552.79.0.81373854185.issue43899@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-04-21 07:02:32serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, alvarezdqal
2021-04-21 07:02:32serhiy.storchakasetmessageid: <1618988552.79.0.81373854185.issue43899@roundup.psfhosted.org>
2021-04-21 07:02:32serhiy.storchakalinkissue43899 messages
2021-04-21 07:02:32serhiy.storchakacreate