comparing two arrays

Scott David Daniels scott.daniels at acm.org
Tue Jun 20 13:41:03 EDT 2006


Diez B. Roggisch wrote:
> Maric Michaud wrote:
> 
>> Le Mardi 20 Juin 2006 12:09, Diez B. Roggisch a écrit :
>>> [i for i, equals in enumerate((x == y for x, y in zip(a, b))) if equals]
>> No needs to nest comprehensions, should be :
>> [ i for i, v in enumerate(zip(a, b)) if v[0] == v[1] ]
> 
> You're right, that design stemmed from my first broken version.

Or even deconstruct to avoid the (very mildly confusing) v[0], v[1]:

     [i for i, (left, right) in enumerate(zip(a, b)) if left == right]

-- 
--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list