Tuesday, October 15, 2013

Howto figure out whether two lists have any elements in common

While working with FragIt I had to figure out whether two lists had some elements in common (it does not matter which!) and I came up with the following piece of code (with the help of Google and Stack Overflow of course)

It takes advantage of the highly underused Sets available in python on which we can do some neat mathematically sane operations. I guess people just go for Lists and work their magic on that.

23 comments:

  1. And just to get fancy:
    shares_elements=lambda a,b: len(set(a)&set(b))>0

    I love lambda expressions ^_^

    ReplyDelete
    Replies
    1. Thats very clever actually! :) thanks for sharing

      Delete
  2. Chem Academy offers Best CSIR NET Coaching in Jaipur and Best coaching institute for CSIR NET at best price. Best coaching for CSIR NET Now available in Jaipur also. CSIR NET Coaching

    ReplyDelete
  3. Science Academy offering Classroom coaching in Jaipur/Delhi, Study Material, Online Test series, Video Classes, Doubt Classes for IIT JAM PHYSICS. Science Academy also available for CSIR NET Entrance Exam at scienceacademy.in Science Academy

    ReplyDelete
  4. Heritage Cabs offers service like Jaipur Car rentalJaipur car hire, taxi hire jaipur car rental service in jaipur @ Rs 8/Km

    ReplyDelete
  5. Innova in jaipur,Innova hire Jaipur, Innova hire Jaipur. Book Innova hire rental service for outstation and Jaipur sightseeing in Jaipur

    ReplyDelete
  6. Innova Hire Jaisalmer,Innova Rental Jaisalmer by Jaisalmer Taxi Tour for Outstation and Sighseeing Purpose. Book Innova on rent Jaisalmer at affordable rates

    ReplyDelete
  7. Gym nearby Gopalpura by Incarnation The Health Club we provide Gym service in Gopalpura bypass (Jaipur), best gym service nearby Gopalpura & Gym service near gopalpura bypass

    ReplyDelete
  8. Our Financial Management services in Mumbai provides you with Financial Management services to provide Financial Services in Mumbai/Jaipur/India

    ReplyDelete
  9. Digital Markeing Company In Jaipur

    Digitalopeners is the best Digital marketing company in jaipur provide Digital Marketing Service in Jaipur and other web services. SEO, SMO, SMM, PPC, Email Marketing, Digital Marketing Service in Jaipur.

    ReplyDelete
  10. Camp In Jaisalmer
    Camp In Jaisalmer Are Offered Heritage juma desert camp. Camp In Jaisalmer Organise Jaisalmer Camps, Desert Camp Jaisalmer, Luxury Camp In jaisalmer Book Now.

    ReplyDelete
  11. Tempo Traveller Rental in Jaipur
    Tempo Traveller Rental Jaipur, Tempo Traveller Hire Jaipur for outstation & sightseeing Purpose, Book Tempo traveller Rental jaipur, Tempo traveller in Jaipur

    ReplyDelete
  12. Ayo Mainkan BvGaming Terbaru dari bolavita... Dengan 1 user ID bisa memainkan semua game yang anda inginkan...

    Info Lengkap Hubungi:
    WA : 0812-2222-995
    Line : cs_bolavita
    Link : BV Gaming

    TERIMA KASIH

    ReplyDelete
  13. Nagaqq Yang Merupakan Agen Bandarq terbaik , Domino 99, Dan Bandar Poker Online Terpercaya di asia hadir untuk anda semua dengan permainan permainan menarik dan bonus menarik untuk anda semua

    Bonus yang diberikan NagaQQ :
    * Bonus rollingan 0.5%,setiap senin di bagikannya
    * Bonus Refferal 10% + 10%,seumur hidup
    * Bonus Jackpot, yang dapat anda dapatkan dengan mudah
    * Minimal Depo 15.000
    * Minimal WD 20.000
    * Deposit via Pulsa TELKOMSEL
    * 6 JENIS BANK ( BCA , BNI, BRI , MANDIRI , CIMB , DANAMON )

    Memegang Gelar atau title sebagai AGEN POKER ONLINE Terbaik di masanya

    12 Games Yang di Hadirkan NagaQQ :
    * Poker Online
    * BandarQ
    * Domino99
    * Bandar Poker
    * Bandar66
    * Sakong
    * Capsa Susun
    * AduQ
    * Perang Bacarrat
    * Perang Dadu
    * BD QQ
    * Adu Sakong (New Game)


    Info Lebih lanjut Kunjungi :
    Website : NAGAQQ
    Facebook : NagaQQ official
    WHATSAPP : +62 87833350051
    Line : Cs_nagaQQ
    TELEGRAM :+855967014811

    ReplyDelete
  14. Desktop Software Development Services
    Satyamev Infotech Pvt. Ltd. desktop software development services in Ahmedabad

    ReplyDelete
  15. When is the right time to employ market research for any business?
    Market research is essential for any business. But its effectiveness is determined by when it is done. Today we will tackle the question of when to do market research for the most rewarding results.

    ReplyDelete