# Enter a code d={ 'Alice':45, 'Bob':60, 'Candy':75, 'David':86, 'Ellena':49 } t = ['Alice', 'Bob', 'Candy', 'Mimi', 'David'] a = 0 while 1: if a <5: print(d.get(t[a])) a += 1 else: break
鄙人想到的一个小方法,想看看还能不能优化
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
a = ['Alice','Bob','Candy','Mimi','David']
for c in a:
print(d.get(c))
d={
'Alice':45,
'Bob':60,
'Candy':75,
'David':86,
'Ellena':49
}
t = ['Alice', 'Bob', 'Candy', 'Mimi', 'David']
for i in t:
print(i,d.get(i))
# Enter a code d = { 'Alice': 45, 'Bob': 60, 'Candy': 75, 'David': 86, 'Ellena': 49 } for name in ['Alice', 'Bob', 'Candy', 'Mimi', 'David']: print(d.get(name))
d={ 'Alice':45, 'Bob':60, 'Candy':75, 'David':86, 'Ellena':49} for key in d : print(d.get(key))
d={ 'Alice':45, 'Bob':60, 'Candy':75, 'David':86, 'Ellena':49 } for key in d.keys(): print(key)