#elements of seq A in seq B

Jan Kaliszewski zuo at chopin.edu.pl
Fri Aug 21 03:42:42 CEST 2009


>>      a = set(a)
>>      n = sum(item in a for item in b)

> Why set?  Does it matter if I say that items in A are already unique?

Sets are hash-based, so it's (most probably) far more efficient for
sets than for sequences (especially if we say about big/long ones).

Regards,
*j

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list