Re: Membership of multiple items to a list

Discussion in 'Python' started by Stephen Hansen, Feb 1, 2009.

  1. -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.10 (Darwin)
    Comment: Public key available at: http://killnine.net/shansen.pub

    iEYEARECAAYFAkmF/4gACgkQEKJsw6Mia26+ngCdEkeE/OiJXbWpABL47QAd7T+X
    u1EAnR/jpjkT1rVnPFRW7iAYGD055h1l
    =E9aU
    -----END PGP SIGNATURE-----
     
    Stephen Hansen, Feb 1, 2009
    #1
    1. Advertising

  2. Stephen Hansen

    inkhorn Guest

    Wow thanks for the lightning fast reply! This does exactly the right
    job.

    Matt

    On Feb 1, 3:01 pm, Stephen Hansen <> wrote:
    > I'd like to know how to elegantly check a list for the membership of
    > any of its items to another list.  Not caring for elegance, I would
    > use the following code:
    > That's one of the useful properties of sets:
    > >>> a = [1,2,3]
    > >>> b = [3,4,5,6]
    > >>> set(a) & set(b)

    > set([3])
    > >>> set(a).intersection(b)

    > set([3])
    > 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.
    > --Stephen
    >
    >  signature.asc
    > < 1KViewDownload
     
    inkhorn, Feb 1, 2009
    #2
    1. Advertising

  3. 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.
    > &nbsp;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>&gt;&gt;&gt; a = [1,2,3]<br>&gt;&gt;&gt; b =
    > [3,4,5,6]<br>&gt;&gt;&gt; set(a) &amp;
    > set(b)<br>set([3])<br>&gt;&gt;&gt;
    > 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) &amp; 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
     
    Steven D'Aprano, Feb 2, 2009
    #3
  4. Stephen Hansen

    Guest

    Quoth Steven D'Aprano <>:
    > 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.
    > > &nbsp;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>&gt;&gt;&gt; a = [1,2,3]<br>&gt;&gt;&gt; b =
    > > [3,4,5,6]<br>&gt;&gt;&gt; set(a) &amp;
    > > set(b)<br>set([3])<br>&gt;&gt;&gt;
    > > 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) &amp; 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
     
    , Feb 2, 2009
    #4
  5. > Stephen, do you see the utter mess your posts look like to some others?

    Whoops, I was experimenting with a new Firefox add-on that fiddled
    with Gmail, and hadn't noticed it changed my output format to HTML out
    from under me.

    Sorry!

    --S
     
    Stephen Hansen, Feb 2, 2009
    #5
  6. On Sun, Feb 1, 2009 at 7:47 PM, Ben Finney
    <> wrote:
    > writes:
    >
    >> I don't even see Stephen Hansen's posts. My newsreader just shows
    >> the header and says "[HTML part not displayed]".

    >
    > Likewise.


    Yeah, I know HTML is bad on newsgroups. I didn't realize that when I
    installed FireGPG to sign messages while in Gmail that it started
    handling my html/plain text content differently.

    Oops.

    That said: Is S/MIME / OpenPGP readable on these various clients?
    There's no HTML, the text body is just encoded in base64.

    I haven't actually subscribed to a usenet newsgroup in eons upon eons.

    If its not readable as S/MIME then I'll switch to inline PGP... that's
    just a slightly terrible solution for other places I have to talk and
    I'll have to take extra care to remember to manually check the
    settings based upon where I'm talking.

    I'm re-sending this same message as the OpenPGP S/MIME attachment
    format -- just so test if its actually readable by news clients in
    general. I have absolutely no idea. Not touched a news client in years
    and years, as I said.

    Sorry for the inconvenience.

    --Stephen
     
    Stephen Hansen, Feb 2, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gilles Kuhn
    Replies:
    0
    Views:
    456
    Gilles Kuhn
    Sep 15, 2003
  2. Anjan Bhowmik
    Replies:
    1
    Views:
    512
    Misbah Arefin
    Feb 14, 2008
  3. divya
    Replies:
    1
    Views:
    1,121
    Munna
    May 28, 2008
  4. inkhorn
    Replies:
    1
    Views:
    251
    Paul Rubin
    Feb 1, 2009
  5. ela
    Replies:
    12
    Views:
    384
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page