目录
77.题目:循环输出列表
78.找到年龄最大的人,并输出。
77.题目:循环输出列表
#77
s = ["man","woman","girl","boy","sister"]
for i in s:print(i)
返回:
或者是
s = ["man","woman","girl","boy","sister"]
for i in range(len(s)):print(s[i])
78.找到年龄最大的人,并输出。
#78
person = {"li":18,"wang":50,"zhang":20,"sun":22}
num = max(person.values()) #取到最大键值
person_ = {v:k for k,v in person.items()} #反键值
print(person_[num],num)
返回:
注:如果存在多个键值相等的话,上述方法只能取到第一个