q1
Given the list of employees defined in the cell below, write python code to:
Notes:
employees = [
{
"email": "christine5663.howard@gmail.com",
"employee_id": 201,
"firstname": "Christine",
"lastname": "Howard",
"title": "Mrs",
"work_phone": "(03) 7465 4973"
},
{
"email": "paula592.campbell@gmail.com",
"employee_id": 202,
"firstname": "Paula",
"lastname": "Campbell",
"title": "Mrs",
"work_phone": "(02) 2128 4700"
},
{
"email": "steve5806.bird@gmail.com",
"employee_id": 203,
"firstname": "Steve",
"lastname": "Bird",
"title": "Mr",
"work_phone": "(03) 3199 8017"
}
]
# Insert all dicts with supplier_id=542 or employee_id=700 to the new list
# Write your code below this line
q2
Given a list of numbers, defined as variable numbers in the cell below, write python code to perform the following:
Skeleton code has been provided in the cell below to facilitate your task.
# 1. Define the function
def list_min(lst):
min = None
# Hint 1:
# Use a loop to process all items in the list
# For each item, check if the item is smaller than the value stored in min
# If it is, then assign the value of the current item to variable min
# If it's not, do nothing
# Hint 2:
# Be careful when comparing the min variable (especially when it is None) to an item in the list
# If you are not careful, your code will crash
# Check how it's done in the Severance book
# Write your code below this line
# Return the smallest value found
return min
# 2. Call the function with the list defined next
numbers = [42, 34, 10, 401, 52100]
# Write your code to call the function below this line
第一个部分代码
employees = [
{
"email": "christine5663.howard@gmail.com",
"employee_id": 201,
"firstname": "Christine",
"lastname": "Howard",
"title": "Mrs",
"work_phone": "(03) 7465 4973"
},
{
"email": "paula592.campbell@gmail.com",
"employee_id": 202,
"firstname": "Paula",
"lastname": "Campbell",
"title": "Mrs",
"work_phone": "(02) 2128 4700"
},
{
"email": "steve5806.bird@gmail.com",
"employee_id": 203,
"firstname": "Steve",
"lastname": "Bird",
"title": "Mr",
"work_phone": "(03) 3199 8017"
}
]
#firstnames Christine or Steve in the new list
new_list = list(filter(lambda x: x["firstname"] in ['Christine','Steve'], employees))
print(len(new_list))
print(new_list)
for item in new_list:
item.update({'supplier_id':542})
item['employee_id']=700
print(new_list)
:
employees = [
{
"email": "christine5663.howard@gmail.com",
"employee_id": 201,
"firstname": "Christine",
"lastname": "Howard",
"title": "Mrs",
"work_phone": "(03) 7465 4973"
},
{
"email": "paula592.campbell@gmail.com",
"employee_id": 202,
"firstname": "Paula",
"lastname": "Campbell",
"title": "Mrs",
"work_phone": "(02) 2128 4700"
},
{
"email": "steve5806.bird@gmail.com",
"employee_id": 203,
"firstname": "Steve",
"lastname": "Bird",
"title": "Mr",
"work_phone": "(03) 3199 8017"
}
]
new_emp_list = list(filter(lambda x: x["firstname"] in {"Christine","Steve"}, employees))
print(len(new_emp_list))
print(new_emp_list)
2
def list_min(lst):
min = None
for n in lst:
if min is None or min > n:
min = n
return min
numbers = [42, 34, 10, 401, 52100]
print(list_min(numbers))
您好,我是问答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632