First different char in two strings?

Darrell Gallion dgallion1 at yahoo.com
Tue May 23 19:00:53 CEST 2000


Emile wrote:
>Ah, but with only a minor mod, time it again: ;-)
>a = "abc"*
>b = a[:-1]+'l'
> 
>for i in range(len(a)-1,0,-1):
>  if b[i] != a[i]:
>    break
>print i
> 
>Life's-easier-when-you-get-to-select-the-test-case-ly
y'rs,
 
I missed the meaning of the ";-)" 
Then didn't read close enough the
"range(len(a)-1,0,-1)"
But your absolutely correct
"Life's-easier-when-you-get-to-select-the-test-case-ly
y'rs"

Unexpectedly the binary search still wins.
Change "range" to "xrange" and it becomes faster.
********
1499999
0.00999999046326 sec Reverse linear
1499999
0.0900000333786 sec Binary search
********

But the strings have to be the same length.


--Darrell Gallion 








__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/




More information about the Python-list mailing list