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? Please ensure you send plain text messages to Usenet, not HTML. If you absolutely can't avoid using an insecure and bloated page layout language instead of text, please ensure that your News or mail client is set to send plain text as well as HTML. If your news/mail client doesn't follow Usenet standards, then (1) change the application you use to one that does; or (2) complain to the vendor until they fix their product. Thank you, -- Steven -- http://mail.python.org/mailman/listinfo/python-list