Comparing strings from the back?

Dan Goodman dg.gmane at thesamovar.net
Mon Sep 10 13:32:48 EDT 2012


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




More information about the Python-list mailing list