Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Previous problem: def name_lists(name_list): d = {} for name in name_list: first

ID: 3707930 • Letter: P

Question

Previous problem:

def name_lists(name_list):

d = {}

for name in name_list:

first_name = name.split()[0]

if first_name not in d:

d[first_name] = 0

d[first_name] += 1

return d

TooManyNames2 py Submit Run Grades Reset 1#Recall in the previous problem 2#instances of a certain first name in a list of full names you counted the number of 3 #You returned a dictionary with the name as the key, and the 4 #number of times it appeared as the value 5# 6#Modify that code such that instead of having a count as the 7#value, you 8#that first name. So, each key in the dictionary would still 9#be a first name, but the values would be lists of names | {David': [David Joyner', "David Zuber'1, 'Nicol['Nicol Barthe 1', 'Shelba: [ Shelba Barthel', Shelba Crowley, Shelba Fernal d', Shelba odle Shelba Fry'1 instead have a list of the full names that had Maren: ['Maren Fry ', 'Brento n: ['Brenton Joyner 'Brenton Z 10#Make sure to sort the list of names, too 12#Name this new function name lists 13#Add your function here! 14 def name lists (name 1ist): 15 my_dict-() 16 17 for name in name list: splity-name.split') first splity[] last-splity[1] 21 if not first in my dict: my_dict[first]-[name] my_dict[first].append (name) 24. else: return my_dict 28#Below are some lines of code that will test your function 29 #You can change the value of the variable(s) to test your 30#function with different inputs 31#If your function works correctly, this will originally 32 #print (although the order of the keys may vary): 33 #{"Shelba": ['Shelba Barthel', 'Shelba Crowley', 'Shelba Fernald", "Shelba Odle', 'Shelba Fry'], 34 #, David. : 35 #"Maren': [ "Maren Fry'], ·Nico1': ['Nicol Barthel.)) vid JoynerDavid Zuber'], Brenton': [ 'Brenton JoynerBrenton Zuber', 37 name list Doyner" "David Zuber "Brenton Joyner", "Brenton Zuber", "Nicol Barthel", "Shelba Barthel", "Shelba Crowley "Shelba Fernald", "Shelba Odle", "Shelba Fry", "Maren Fry" 41 print (name_lists(name_list))

Explanation / Answer

def name_lists(name_list): d = {} for name in name_list: first_name = name.split()[0] if first_name not in d: d[first_name] = [] d[first_name].append(name) d[first_name] = sorted(d[first_name]) return d print(name_lists(['David Zuber', 'David Joyner', 'Brenton Zoyner']))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote