Compsci 101, mapNameToNumberLastNames
This exercise is for collaborative work during class. Do not fill out early!
Sign in to Google to save your progress. Learn more
Consider the following code segments for mapping first names to the number of last names that go with it.
A)
def mapNameToNumberLastNames(data):
    countmap = {}
    for [first, last] in data:
        countmap[first] = 1
        countmap[first] += 1
    return countmap

B)
def mapNameToNumberLastNames(data):
    countmap = {}
    for [first, last] in data:
        countmap[first] += 1
    return countmap

C)
def mapNameToNumberLastNames(data):
    countmap = {}
    for [first, last] in data:
        if first in countmap:
            countmap[first] = countmap[first] + 1
        else:
            countmap[first] = 1
    return countmap

D)
def mapNameToNumberLastNames(data):
    countmap = {}
    for [first, last] in data:
        if first not in countmap:
            countmap[first] = 0
        countmap[first] += 1
    return countmap



Which one of the following correctly build a dictionary mapping first names to the number of last names that correspond? *
Required
Names and Netids below
Names (comma separated) *
netid *
netid (partner)
netid (partner)
netid (partner)
Submit
Clear form
Never submit passwords through Google Forms.
This content is neither created nor endorsed by Google. Report Abuse - Terms of Service - Privacy Policy