Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

flip key and value in dictionary python

# flip key and values
by_name = {"Negative": -1, "Positive": 1, "Neutral": 0, "Mixed": 2}
by_num = {value: key for key, value in by_name.items()}
# ouput = {-1: 'Negative', 1: 'Positive', 0: 'Neutral', 2: 'Mixed'}
 
PREVIOUS NEXT
Tagged: #flip #key #dictionary #python
ADD COMMENT
Topic
Name
5+8 =