Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subsequent': 0.04; 'computed': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stored': 0.10; 'benjamin': 0.16; 'iterating': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'string': 0.17; 'wrote:': 0.17; 'code.': 0.20; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'creating': 0.26; '[1]': 0.27; 'header:X -Complaints-To:1': 0.28; 'clever': 0.29; 'comparison': 0.29; 'dan': 0.29; 'hash': 0.29; 'that.': 0.30; '(and': 0.32; 'computing': 0.32; 'to:addr:python-list': 0.33; 'doing': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'but': 0.36; 'characters': 0.36; 'itself': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'worth': 0.63; 'costs': 0.64; 'received:109': 0.74; 'oscar': 0.84; 'average': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dan Goodman Subject: Re: Comparing strings from the back? Date: Mon, 10 Sep 2012 19:32:48 +0200 References: <504E104D.8090404@thesamovar.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 226.49.9.109.rev.sfr.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347298387 news.xs4all.nl 6857 [2001:888:2000:d::a6]:60905 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28837 On 10/09/2012 18:33, Oscar Benjamin wrote: > Computing the hash always requires iterating over all characters in the string > so is best case O(N) where string comparison is best case (and often average > case) O(1). Yep, but you already have O(N) costs just creating the strings in the first place, so it's absorbed into that. It's only worth doing if you do many comparisons. > Also, so far as I know the hash value once computed is stored on the string > object itself [1] and used for subsequent string comparisons so there's no > need for you to do that in your code. Cool, Python is very clever as always! :) Dan