[Python-ideas] exclusively1, common, exclusively2 = set1 - set2, set1 & set2, set2 - set1
Juancarlo Añez
apalala at gmail.com
Thu Jul 4 03:41:21 CEST 2013
On Wed, Jul 3, 2013 at 7:46 PM, Oscar Benjamin
<oscar.j.benjamin at gmail.com>wrote:
> def partition(setx, sety):
> xonly, xandy, yonly = set(), set(), set()
> for set1, set2, setn in [(setx, sety, xonly), (sety, setx, yonly)]:
> for val in set1:
> if val in set2:
> xandy.add(val)
> else:
> setn.add(val)
> return xonly, xandy, yonly
>
I don't understand why that can be more efficient that using the built-in
operations:
def partition(setx, sety):
common = setx & sety
return setx - common, common, sety - common
I assume that the built-in operations traverse over the set with the
smallest size, and preallocate the result to that size.
--
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130703/e88b0ef1/attachment-0001.html>
More information about the Python-ideas
mailing list