Page 1 of 1

create_names_dictionary(initials_list, names_list) which takes a list of initials and a list of Write a function named n

Posted: Tue May 24, 2022 8:43 am
by answerhappygod
Create Names Dictionary Initials List Names List Which Takes A List Of Initials And A List Of Write A Function Named N 1
Create Names Dictionary Initials List Names List Which Takes A List Of Initials And A List Of Write A Function Named N 1 (173.46 KiB) Viewed 20 times
create_names_dictionary(initials_list, names_list) which takes a list of initials and a list of Write a function named names as parameters. The function returns a dictionary by looping through each element in the first and the second list and creating a corresponding key:value item. The 'key' of each item in the dictionary is the initials of the first name and surname, and the 'value' is the name (e.g. key of 'AW', value of 'Alex Wong'). For example, the following code: ['Abby Anderson', 'Bella Campbell'] names_list = initials = ['AA', 'BC'] my_dictionary = create_names_dictionary(initials, names_list) print (my_dictionary) produces {'AA': 'Abby Anderson', 'BC': 'Bella Campbell'} You can assume that both parameters are the same length and that the initials_list does not contain any duplicates. For example: Test Result AA Abby Anderson names_list = ['Abby Anderson', 'Bella Campbell', 'Charlotte Donovan'] ['AA', 'BC', 'CD'] initials = BC Bella Campbell my_dictionary = create_names_dictionary (initials, names_list) CD Charlotte Donovan for letter in sorted(my_dictionary.keys()): print(letter, my_dictionary [letter])