Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python dictionary get vs setdefault

# setdefault will insert key with a value of default
# get will not insert key

a = {}
b = a.get('key','value')
print(a,b)
# {} value

a = {}
b = a.setdefault('key','value')
print(a,b)
# {'key': 'value'} value
Comment

PREVIOUS NEXT
Code Example
Python :: df iloc 
Python :: airflow schedule interval timezone 
Python :: python cassandra 
Python :: how to repeat a row in pandas 
Python :: import excel 
Python :: support vector machine example 
Python :: joblib example 
Python :: pubg python 
Python :: to get the number of unique values for each column 
Python :: numeric up down python tkinter 
Python :: data types in numpy array 
Python :: lru_cache 
Python :: python if string has spaces 
Python :: pydrive download by url 
Python :: python program to demonstrate scoping 
Python :: key pressed pygame 
Python :: append to list at index python 
Python :: find item in list 
Python :: python invert colormap 
Python :: ner spacy 
Python :: how to find duplicates in csv file using python 
Python :: python secret 
Python :: Python Tkinter MenuButton Widget 
Python :: use latest file on aws s3 bucket python 
Python :: how to make an array python 
Python :: parse_dates 
Python :: python set split limit 
Python :: extracting values in pandas 
Python :: windows instalar python 
Python :: pandas read csv with lists 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =