[Tutor] Detecting different list elements and counting them
Zak Arntson
zak at harlekin-maus.com
Thu Dec 11 18:25:41 EST 2003
Hey! And this solves the "count number of matching items in two lists"
nicely:
###
def count(alist, blist):
clist = alist + blist
adict = {}
for key in clist:
if key not in adict: adict[key] = 0
else: adict[key] += 1
return reduce(lambda x, y: x + y, adict.values())
###
---
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em
More information about the Tutor
mailing list