Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python replace by dictionary

address = "123 north anywhere street"

for word, initial in {"NORTH":"N", "SOUTH":"S" }.items():
    address = address.replace(word.lower(), initial)
print address
Comment

replace key of dictionary python

a_dict = {"a": 1, "B": 2, "C": 3}

new_key = "A"
old_key = "a"
a_dict[new_key] = a_dict.pop(old_key)

print(a_dict)
OUTPUT
{'B': 2, 'C': 3, 'A': 1}
Comment

PREVIOUS NEXT
Code Example
Python :: change value in excel using python 
Python :: OneHotEncoder() 
Python :: cv2.namedWindow 
Python :: python series to list of string 
Python :: python set day of date to 1 
Python :: django static files 
Python :: add x=y line to scatter plot python 
Python :: django queryset last 10 
Python :: scaling data 
Python :: pandas groupby mean 
Python :: pandas dataframe get number of occurrence in column 
Python :: find the index of a character in a string python 
Python :: keep only one duplicate in pandas 
Python :: how to give autocomplete in python 
Python :: how does urllib.parse.urlsplit work in python 
Python :: abc python 
Python :: python if in range 
Python :: 3 dimensional array in numpy 
Python :: how to add window background in pyqt5 
Python :: cd in python 
Python :: python default dic 
Python :: python stack 
Python :: how to import numpy in python 
Python :: relative path django 
Python :: How to wait a page is loaded in Python Selenium 
Python :: pandas earliest date in column 
Python :: access row of dataframe 
Python :: python plot groupby colors 
Python :: python face recognition 
Python :: python mettre en minuscule 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =