#elements of seq A in seq B

Jan Kaliszewski zuo at chopin.edu.pl
Fri Aug 21 01:44:43 CEST 2009

20-08-2009 o 13:01:29 Neal Becker <ndbecker2 at gmail.com> wrote:

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


1) separately for each element of A? (see Simon's sollution with

2) or total number of all occurrences of elements of A? (see below)

20-08-2009 o 14:05:12 Peter Otten <__peter__ at web.de> wrote:

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

Nice, though I'd prefer Simon's sollution:

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


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

More information about the Python-list mailing list