On Sun, 10 Aug 2008 23:14:50 -0700, ssecorp wrote: > I know zip but lets say I have a word "painter" and I want to compare it > to a customer's spelling, he might have written "paintor" and I want to > check how many letters are the same. > > Now I know how I could do this, it is not hard. I am just wondering if > these is any specific simple syntax for it.
No special syntax for that, but you can combine the `sum()` function, a generator expression and `zip()`: In [40]: sum(int(a == b) for a, b in zip('painter', 'paintor')) Out[40]: 6 Or this way if you think it's more clear: In [41]: sum(1 for a, b in zip('painter', 'paintor') if a == b) Out[41]: 6 Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list