On Aug 19, 4:19 pm, 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).

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import collections
>>> A = 'abc'
>>> B = 'abracadabra'
>>> collections.Counter(filter(A.__contains__, B))
Counter({'a': 5, 'b': 2, 'c': 1})


Raymond
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to