Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python update dict if key not exist

d.setdefault('k1', 100)
print(d)
# {'k1': 1, 'k2': 2, 'k3': 3, 'k4': None}
Source by note.nkmk.me #
 
PREVIOUS NEXT
Tagged: #python #update #dict #key #exist
ADD COMMENT
Topic
Name
1+6 =