#elements of seq A in seq B

Jan Kaliszewski zuo at chopin.edu.pl
Thu Aug 20 21:42:42 EDT 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