print(d.get('Alice', 'Bob', 'Candy', 'Mimi', 'David'))
有没有办法一次性get所有的,当然上面这句没通过。。。
students = ['Alice', 'Bob', 'Candy', 'Mimi', 'David']
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for i in students:
print(d.get(i))
for key in d.keys():
print(key,d.get(key))
d = {'Alice': 45,'Bob': 60,'Candy': 75,'David': 86,'Ellena': 49} name = ['Alice','Bob','Candy','David','Mimi'] for item in name: if item in d: print(item,d.get(item)) else: print('None')
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49,
'Gaven': 86
}
for k in d:
print(k,d.get(k))
把名字加入列表,循环列表get