Calculating string difference in python
Question: I am trying to calculate the number of characters that differ between two
strings in python. Ideally I want a function just like strdif in C. I see
ndiff in python's difflib, but that returns a Differ object whereas I want a
simple integer (ex: "10011" vs "00110" returns 3). I know the answer must be
simple, but I can't figure it out and Id rather use the library function
instead of write it myself


Answer: 
    s1,s2 = "10011", "00110"
    print sum(a!=b for a,b in zip(s1,s2)) + abs(len(s1)-len(s2))
    

should work fine.

or as John Clements points out

    
    
    print sum(a!=b for a,b in map(None,s1,s2))
    

which avoids the extra length check ... and will be slightly faster if the
strings are typically the same length (and its an awesome solution!) ...

or even more terse (now its starting to enter black magic land where enough
reader comprehension is lost that I would probably not recommend actually
implementing it like this in anything that may be seen by others, and if you
do make sure to add lots of comments)

    
    
    from operator import ne
    print sum(map(ne, s1, s2))
    

