ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved