Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'character,': 0.07; 'python': 0.09; 'booth': 0.09; 'expense': 0.09; 'insertion': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'equal.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'unequal': 0.16; 'mon,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'differ': 0.17; 'pointer': 0.17; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'decide': 0.28; 'character.': 0.29; 'comparison': 0.29; "d'aprano": 0.29; 'dictionary': 0.29; 'inspect': 0.29; 'steven': 0.29; 'could': 0.32; 'to:addr:python-list': 0.33; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'created': 0.36; 'but': 0.36; 'compare': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'needing': 0.62; 'received:ac.uk': 0.65; 'guaranteed': 0.76; 'gelonida': 0.84; 'oscar': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Oscar Benjamin Subject: Re: Comparing strings from the back? Date: Mon, 10 Sep 2012 14:06:16 +0000 (UTC) References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: enm-ob.enm.bris.ac.uk User-Agent: slrn/0.9.9p1/mm/ao (Win32) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347285990 news.xs4all.nl 6978 [2001:888:2000:d::a6]:49024 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28820 On 2012-09-10, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 08:59:37 +0000, Duncan Booth wrote: > >> Gelonida N 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