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

Suppose d is a dictionary that maps some employee IDs (a subset of the integers

ID: 3584826 • Letter: S

Question

Suppose d is a dictionary that maps some employee IDs (a subset of the integers from 0 to n1) to salaries. Suppose L is an n-element list whose i-th element is the name of employee number i. Your goal is to write a comprehension whose value is a dictionary mapping employee names to salaries. You can assume that employee names are distinct. However, not every employee ID is represented in d. Test your comprehension with the following data: id2salary = {0:1000.0, 3:990, 1:1200.50} names = ['Larry', 'Curly', '', 'Moe']

Explanation / Answer

Below is the required comprehension: id2salary = {0: 1000.0, 3: 990, 1: 1200.50} names = ['Larry', 'Curly', '', 'Moe'] name2salary = {names[i]: id2salary[i] for i in range(0, len(names)) if i in id2salary} print(name2salary)

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