can you write a str.replace() using dictionary values in Python?
I have to replace the north, south, etc with N S in address fields. If I have list = {'NORTH':'N','SOUTH':'S','EAST':'E','WEST':'W'} address = "123 north anywhere street" Can I for iterate over my dictionary values to replace my address field? for dir in list[]: address.upper().replace(key,value) I know i'm not even close!! But any input would be appreciated if you can use dictionary values like this. address = "123 north anywhere street" for word, initial in {"NORTH":"N", "SOUTH":"S" }.items(): address = address.replace(word.lower(), initial) print address nice and concise and readable too.