This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: items return (key,value) pairs Iteritems return (key,value) pairs more efficiently update update with another dictionary Change Astrachans value somemap[Astrachan] = Coffee Mocha Value could be a set or list Back to Popular Name Problem: Given a list of names, determine the most popular first name and print that name with all of its last names. Input: Names are always two words, names are in a file. If multiple names are on the same line they are separated by a : Output: Most popular first name, followed by a :, followed by corresponding last names separated by a blank Now use a dictionary/map We will write three maps for practice First name to count of corresponding last names First name to list of corresponding last names First name to set of corresponding last names Which map is most useful to solve this problem? Compare Using two parallel lists? Using one dictionary/map...
View Full Document
- Fall '09