Python sprawdź, czy istnieje klucz
# You can use 'in' on a dictionary to check if a key exists
d = {"key1": 10, "key2": 23}
"key1" in d
# Output:
# True
SkelliBoi
# You can use 'in' on a dictionary to check if a key exists
d = {"key1": 10, "key2": 23}
"key1" in d
# Output:
# True
d = {"apples": 1, "banannas": 4}
# Preferably use .keys() when searching for a key
if "apples" in d.keys():
print(d["apples"])
dict = {"key1": 1, "key2": 2}
if "key1" in dict:
print dict["key1]
>> 1
val = dict.get(key , defVal) # defVal is a default value if key does not exist
if word in data:
return data[word]
else:
return "The word doesn't exist. Please double check it."
dict = { "How":1,"you":2,"like":3,"this":4}
key = "this"
if key in dict.keys():
print("present")
print("value =",dict[key])
else:
print("Not present")