def contains(dict, key):
return key in dict
dict={}
dict['a']=1
dict['b']=2
dict['c']=3
print(contains(dict, 'a')) # True
print(contains(dict, 'd')) # False
Search This Blog
Showing posts with label dictionary. Show all posts
Showing posts with label dictionary. Show all posts
Python: test if a dictionary contains a specific key
python: dictionary comprehension
dict = { 'a':1, 'b':2 }
dict = { k: str(dict[k]) for k in dict.keys() }
print(dict)
Python: iterate over dictionary
for name in dict.keys():
print(name)
print(dict[name])
values = [ dict[name] for name in dict.keys() ]
Subscribe to:
Posts (Atom)