[Tutor] Using the set.difference method with an unknown number of input iterables

Ryan Waples ryan.waples at gmail.com
Thu Oct 18 19:56:22 CEST 2012


cheers, much appreciated

-ryan

On Thu, Oct 18, 2012 at 10:52 PM, Emile van Sebille <emile at fenx.com> wrote:

> On 10/18/2012 10:38 AM, Ryan Waples wrote:> I'm struggling to understand
> how to understand/accomplish the following:
>
> >
> > I have an set ("a" below) and a list of sets ("not_a"), how can I pass
> > the elements of "not_a" to set.difference() so that it it understands I
> > want the difference between set "a" and all the rest
> >
> > set.difference says "Changed in version 2.6: Accepts multiple input
> > iterables".
> > How can I give it multiple input iterables?
> >
> > I get different error msgs depending on what I try, but they just tell
> > me that there is something that I'm missing here.
> >
> > Thanks
> >
> > #Code below
> > a = set([1,2,3,4])
> > b = set([2,3,4,5])
> > c = set([3,4,5,6])
> > d = set([4,5,6,7])
> >
> > not_a = [b,c,d]
> > a.difference(not_a)
>
> Try this as
>
> a.difference(*not_a)
>
> The '*' expands the list to its individual items.
>
> HTH,
>
> Emile
>
>
>
> >
> > # I expect to return set([1]), the same as if I called:
> > a.difference(b,c,d)
> >
> >
> >
> >
> > ______________________________**_________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
> >
>
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121018/06e29fa9/attachment.html>


More information about the Tutor mailing list