newb: comapring two strings

Justin Azoff justin.azoff at gmail.com
Fri May 19 02:41:36 CEST 2006


manstey wrote:
> Hi,
>
> Is there a clever way to see if two strings of the same length vary by
> only one character, and what the character is in both strings.
>
> E.g. str1=yaqtil str2=yaqtel
>
> they differ at str1[4] and the difference is ('i','e')

something like this maybe?

>>> str1='yaqtil'
>>> str2='yaqtel'
>>> set(enumerate(str1)) ^ set(enumerate(str2))
set([(4, 'e'), (4, 'i')])
>>>

-- 
- Justin




More information about the Python-list mailing list