Re: [Tutor] Detecting different list elements and counting them
by Zak Arntson other posts by this author
Dec 11 2003 11:25PM messages near this date
Re: [Tutor] Detecting different list elements and counting them
|
RE: [Tutor] Detecting different list elements and counting them
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
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Michael Grabietz
Alan Gauld
Terry Carroll
Zak Arntson
Edward Comber
|