#elements of seq A in seq B

Peter Otten __peter__ at web.de
Thu Aug 20 08:05:12 EDT 2009


Neal Becker wrote:

> I meant #occurrences of characters from the set A in string B

If a contains "few" characters:

n = sum(b.count(c) for c in a)

If a contains "many" characters:

identity = "".join(map(chr, range(256)))
n = len(b) - len(b.translate(identity, a))

Peter





More information about the Python-list mailing list