Membership of multiple items to a list

rdmurray at bitdance.com rdmurray at bitdance.com
Sun Feb 1 22:11:39 EST 2009


Quoth Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au>:
> On Sun, 01 Feb 2009 12:01:11 -0800, Stephen Hansen wrote:
> 
> > <br><div class="gmail_quote"><blockquote class="gmail_quote"
> > style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt
> > 0.8ex; padding-left: 1ex;"><br> I'd like to know how to elegantly check
> > a list for the membership of<br> any of its items to another list.
> >  Not caring for elegance, I would<br> use the following code:<br>
> > </blockquote><div><br>That's one of the useful properties of
> > sets:<br><br>>>> a = [1,2,3]<br>>>> b =
> > [3,4,5,6]<br>>>> set(a) &
> > set(b)<br>set([3])<br>>>>
> > set(a).intersection(b)<br>set([3])<br> <br>That's two spellings of the
> > same thing. As for testing: an empty set like an empty list will return
> > false, so "if set(a) & set(b):" will be true or false based on if
> > there's any commonalities between the two
> > lists.<br><br>--Stephen</div></div><br>
> 
> 
> Stephen, do you see the utter mess your posts look like to some others?

I don't even see Stephen Hansen's posts.  My newsreader just shows the
header and says "[HTML part not displayed]".

--RDM




More information about the Python-list mailing list