20-08-2009 o 01:19:24 Neal Becker <ndbeck...@gmail.com> wrote:

What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B?  (in this particular case, these
sequences are strings, if that matters).

If you mean: to count occurences of each element of A (separately) in B...

Hm, maybe something like this:

  # result as a dict {<element of A>: <how many occurences in B>, ...}
  dict((element, B.count(element)) for element in A)


If you mean: to count non overlaping occurences of string A in B
-- simply:

  B.count(A)


Regards,
*j

--
Jan Kaliszewski (zuo) <z...@chopin.edu.pl>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to