20-08-2009 o 04:12:14 Simon Forman <sajmik...@gmail.com> wrote:

If you want to know the count for each element you can use this:

from collections import defaultdict

def g(a, b):
    a = set(a)
    d = defaultdict(int)
    for item in b:
        if item in a:
            d[item] += 1
    return d

print g(A, B)

# prints defaultdict(<type 'int'>, {' ': 1, 'e': 1, 'g': 1, 'i': 1,
'o': 1, 'n': 2, 's': 1, 'r': 2, 't': 2})

Yeah, your sollution is better (and more interesting :-)). Thanks!

*j

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

Reply via email to