Livejournal
Log in
Post
Friends
My journal
aklepatc
Python: partition an iterable
Sep 28, 2015 20:43
"Partition" an iterable into two sets according to some predicate. (Ab)using the fact that set.add returns None.
bad = set()
good = {x for x in it if is_good(x) or bad.add(x)}
python
Leave a comment
Read comments 2
Previous post
Next post
Up