Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17852
| References | <th7hs8-one.ln1@chris.zbmc.eu> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2011-12-24 08:57 -0700 |
| Subject | Re: How to check for single character change in a string? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4051.1324742254.27778.python-list@python.org> (permalink) |
On Sat, Dec 24, 2011 at 8:26 AM, <tinnews@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 > > > Note that position is significant, a character in a different position > should not count as a match. > > Is there any simpler/neater way than just a for loop running through > both strings and counting non-matching characters? No, but the loop approach is pretty simple: sum(a == b for a, b in zip(str1, str2))
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to check for single character change in a string? tinnews@isbd.co.uk - 2011-12-24 15:26 +0000
Re: How to check for single character change in a string? Roy Smith <roy@panix.com> - 2011-12-24 10:57 -0500
Re: How to check for single character change in a string? Roy Smith <roy@panix.com> - 2011-12-24 11:10 -0500
Re: How to check for single character change in a string? Arnaud Delobelle <arnodel@gmail.com> - 2011-12-24 17:09 +0000
Re: How to check for single character change in a string? Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-24 10:22 -0800
Re: How to check for single character change in a string? tinnews@isbd.co.uk - 2011-12-26 22:37 +0000
Re: How to check for single character change in a string? Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-24 08:57 -0700
csiph-web