for x,y in word1, word2 ?

Edwin.Madari at VerizonWireless.com Edwin.Madari at VerizonWireless.com
Mon Aug 11 08:23:05 EDT 2008


sounds like *soundex* is what you are looking for.  google soundex

regards
Edwin

-----Original Message-----
From: python-list-bounces+edwin.madari=verizonwireless.com at python.org
[mailto:python-list-bounces+edwin.madari=verizonwireless.com at python.org]
On Behalf Of Marc 'BlackJack' Rintsch
Sent: Monday, August 11, 2008 3:09 AM
To: python-list at python.org
Subject: Re: for x,y in word1, word2 ?


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



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.





More information about the Python-list mailing list