Re: How to check for single character change in a string?

2011-12-26 Thread tinnews
Roy Smith r...@panix.com wrote: In article roy-aaaeea.10571424122...@news.panix.com, Roy Smith r...@panix.com wrote: len([x for x in zip(s1, s2) if x[0] != x[1]]) Heh, Ian Kelly's version: sum(a == b for a, b in zip(str1, str2)) is cleaner than mine. Except that Ian's counts

How to check for single character change in a string?

2011-12-24 Thread tinnews
Can anyone suggest a simple/easy way to count how many characters have changed in a string? E.g. giving results as follows:- abcdefg abcdefh 1 abcdefg abcdekk 2 abcdefg gfedcba 6 Note that position is significant, a character in a different

Re: How to check for single character change in a string?

2011-12-24 Thread Ian Kelly
On Sat, Dec 24, 2011 at 8:26 AM, tinn...@isbd.co.uk wrote: Can anyone suggest a simple/easy way to count how many characters have changed in a string? E.g. giving results as follows:-    abcdefg     abcdefh         1    abcdefg     abcdekk         2    abcdefg     gfedcba         6

Re: How to check for single character change in a string?

2011-12-24 Thread Roy Smith
In article th7hs8-one@chris.zbmc.eu, tinn...@isbd.co.uk wrote: Can anyone suggest a simple/easy way to count how many characters have changed in a string? Depending on exactly how you define changed, you're probably talking about either Hamming Distance or Levenshtein Distance. I would

Re: How to check for single character change in a string?

2011-12-24 Thread Roy Smith
In article roy-aaaeea.10571424122...@news.panix.com, Roy Smith r...@panix.com wrote: len([x for x in zip(s1, s2) if x[0] != x[1]]) Heh, Ian Kelly's version: sum(a == b for a, b in zip(str1, str2)) is cleaner than mine. Except that Ian's counts matches and the OP asked for non-matches,

Re: How to check for single character change in a string?

2011-12-24 Thread Arnaud Delobelle
On 24 December 2011 16:10, Roy Smith r...@panix.com wrote: In article roy-aaaeea.10571424122...@news.panix.com,  Roy Smith r...@panix.com wrote: len([x for x in zip(s1, s2) if x[0] != x[1]]) Heh, Ian Kelly's version: sum(a == b for a, b in zip(str1, str2)) is cleaner than mine.  Except

Re: How to check for single character change in a string?

2011-12-24 Thread Rick Johnson
On Dec 24, 11:09 am, Arnaud Delobelle arno...@gmail.com wrote: sum(map(str.__ne__, str1, str2)) Mirror, mirror, on the wall. Who's the cleanest of them all? -- http://mail.python.org/mailman/listinfo/python-list