题目
题目
单项选择题

Question11 employeeData = { 'E001': ['Alice', 'HR', 70000], 'E002': ['Bob', 'Finance', 82000], 'E003': ['Carol', 'IT', 91000], 'E004': ['David', 'Marketing', 76000], 'E005': ['Eva', 'IT', 88000] }  The dictionary employeeData has been created as the above code (please note the employee IDs are the keys in the dictionary. For example, ‘E001’ is an employee ID.). To store all employee IDs in a new list, what is the missing line of code in the second line of the following code? emp_ids = [] # the missing line of code emp_ids.append(emp_id) Select one alternative: for emp_id in employeeData.items(): for emp_id in employeeData.values(): for emp_id in employeeData: for emp_id in employeeData.keys(): ResetMaximum marks: 2 Flag question undefined

选项
A.for emp_id in employeeData.items():
B.for emp_id in employeeData.values():
C.for emp_id in employeeData:
D.for emp_id in employeeData.keys():
查看解析

查看解析

标准答案
Please login to view
思路分析
The question shows a Python dictionary where employeeData uses IDs like 'E001' as keys and lists as values. The task is to store all employee IDs in a new list by iterating over the dictionary in a particular way, and the missing line should be placed after emp_ids = []. Option A: for emp_id in employeeData.items(): - This iterates over (key, value) tuples, not just the keys. If you then do emp_ids.append(emp_id), you would append tuples like ('E001', ['A......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!