How safely remove a key from a dictionary if it might not exist in Python

1 Answer

0 votes
keys = ['key1', 'key2', 'key3', 'key4']

dic = {key: [0, 0] for key in keys}

print(dic)

 
 
'''
run:
 
{'key1': [0, 0], 'key2': [0, 0], 'key3': [0, 0], 'key4': [0, 0]}

'''

 



answered Dec 17, 2024 by avibootz
edited Dec 17, 2024 by avibootz

Related questions

...