[Python-ideas] exclusively1, common, exclusively2 = set1 - set2, set1 & set2, set2 - set1

Paddy3118 paddy3118 at gmail.com
Sun Jul 7 07:28:23 CEST 2013



On Sunday, 7 July 2013 03:53:09 UTC+1, David Mertz wrote:
>
> <snip>
>
  from collections import segment  # tentative name, see various 
> suggestions in thread
>   only1, only2, intersection = segment(iter1, iter2)
>
> In behavior, this should do the same thing as the below (just faster):
>
>   def segment(iter1, iter2):
>       set1, set2 = map(set, (iter1, iter2))
>       return set1 - set2, set2 - set1, set1 & set2
>
 
Hi David, I really am not sure about generalizing the interface to 
iterators and then immediately turning them into sets in the 
implementation. I think the functionality can be naturally explained as an 
operation on two sets and should be restricted to sets. The caller should 
have to map other types to sets explicitly. 

If it turns out that the implemented algorithm in C would work just as well 
with one of the arguments being any finite iterator and the other needing 
to be a set then we could still stick with requiring two sets or change to 
a format of:

set_only, common, iter_only = some_set.????(some_iterator)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130706/d8b1b289/attachment-0001.html>


More information about the Python-ideas mailing list