On 2012-09-10, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > On Mon, 10 Sep 2012 08:59:37 +0000, Duncan Booth wrote: > >> Gelonida N <gelon...@gmail.com> wrote: >> >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on all >> the comparisons. > > What interning buys you is that "s == t" is an O(1) pointer compare if > they are equal. But if s and t differ in the last character, __eq__ will > still inspect every character. There is no way to tell Python "all > strings are interned, if s is not t then s != t as well". >
I thought that if *both* strings were interned then a pointer comparison could decide if they were unequal without needing to check the characters. Have I misunderstood how intern() works? Oscar -- http://mail.python.org/mailman/listinfo/python-list