best way to compare contents of 2 lists?

Discussion in 'Python' started by Esmail, Apr 24, 2009.

  1. Esmail

    Esmail Guest

    What is the best way to compare the *contents* of two different
    lists regardless of their respective order? The lists will have
    the same number of items, and be of the same type.

    E.g. a trivial example (my lists will be larger),

    a=[1, 2, 3]

    b=[2, 3, 1]

    should yield true if a==b

    I suppose I could sort them and then compare them. I.e.,

    sorted(a)==sorted(b)


    I am wondering if there is a more efficient/preferred way to do so.

    Thanks,
    Esmail
     
    Esmail, Apr 24, 2009
    #1
    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. Robin Siebler
    Replies:
    6
    Views:
    5,508
    Raymond Hettinger
    Sep 15, 2004
  2. Esmail
    Replies:
    3
    Views:
    392
  3. Esmail
    Replies:
    6
    Views:
    280
    Terry Reedy
    Apr 24, 2009
  4. norseman
    Replies:
    3
    Views:
    1,070
    ajaksu
    Apr 24, 2009
  5. Zachary Dziura
    Replies:
    12
    Views:
    474
    Chris Angelico
    Jun 13, 2011
Loading...

Share This Page