用列表查字典
dict1 = {"a":1,"b":5,"c":9}f = ["a","b","c"]
print( for _ in f])#1,5,9
但如果f = ["a","b","c","g"]
就会报错,请问有更好的用列表查询字典的方法吗? list(map(lambda _:dict1.get(_),f))
dict1 = {"a":1,"b":5,"c":9}
f = ["a","b","c","g"]
返回
方法一:
dict1 = {"a":1,"b":5,"c":9}
f = ["a","b","c","g"]
print()# 如果获取的不存在时会返回一个默认值 None。
# 输出结果:
方法二:
dict1 = {"a":1,"b":5,"c":9}
f = ["a","b","c","g"]
b =
print(b)
# 输出结果: 不清楚你想要什么,希望对你有帮助dict1 = {"a": 1, "b": 5, "c": 9}
print(*dict1.values())1 5 9
页:
[1]