eryksun wrote: > On Thu, Oct 25, 2012 at 3:46 PM, Prasad, Ramit > <ramit.pra...@jpmorgan.com> wrote: > > > > Do you happen to know offhand if there is a difference between > > `in <list>` vs. `in <tuple>` vs. `in <set>`? > > The "in" comparison (__contains__ method) is equivalent for list and > tuple. It has to search through the sequence item by item, which makes > it an O(n) operation. On the other hand, a set/dict uses the hash() of > an object to map it to a known location in a table (performance > degrades if there are many collisions). On average, you can check if a > set/dict contains an item in constant time, i.e. O(1). The amortized > worst case is O(n).
Sorry, I should have stated that I meant with regards to the optimization that loads these as a literal constant. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor