1. 程式人生 > >Phthon函數之一——取字典中的條件key

Phthon函數之一——取字典中的條件key

字典 items print for key get key值 keys ems

取字典info中值為10000的key值:
def getkeys(key):
info = {"劉江紅": 12000, "曹俊傑": 10000, "趙磊": 10000}
for i in info.keys():
if info[i] == key:
print(i)
getkeys(10000)
取字典info中值大於10010的key值:
def getkeys(v):
info = {"劉江紅": 12000, "曹俊傑": 11000, "趙磊": 10000}
info["李俊"] = 10000
for i,key in info.items():
if info[i] == key and key > v:
print(i)
getkeys(10010)

Phthon函數之一——取字典中的條件key