#elements of seq A in seq B

Peter Otten __peter__ at web.de
Thu Aug 20 14:05:12 CEST 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))


More information about the Python-list mailing list