Compsci 101, mapNameToListOfLastNames
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 list of corresponding last names
A)
def  mapNameToLastNames(data):
    namemap = { }
    for [first,last] in data:
        alist = namemap[first]
        alist.append(last)
    return namemap

B)
def  mapNameToLastNames(data):
    namemap = { }
    for [first,last] in data:
        if first not in namemap:
            namemap[first] =  [ ]
        alist = namemap[first]
        alist.append(last)
    return namemap

C)
def  mapNameToLastNames(data):
    namemap = { }
    for [first,last] in data:
        if first not in namemap:
            namemap[first] = [last]
        else:
            namemap[first].append(last)
    return namemap


D)
def  mapNameToLastNames(data):
    namemap = { }
    for [first,last] in data:
        if first not in namemap:
            namemap[first] = [ ]
        namemap[first].append(last)
    return namemap





Which one of the following correctly build a dictionary mapping first names to the list of their corresponding last names? *
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