regards
Edwin
-----Original Message-----
From: py************************************************ **@python.org
[mailto:py***************************************** *********@python.org]
On Behalf Of Marc 'BlackJack' Rintsch
Sent: Monday, August 11, 2008 3:09 AM
To: py*********@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 itNo special syntax for that, but you can combine the `sum()` function, a
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.
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.