Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- str.replace("USA", "United States of America")
- str.replace("CAN", "Canada")
- str.replace("BHM", "Bahamas")
- str.replace("CUB", "Cuba")
- str.replace("HAI", "Haiti")
- str.replace("DOM", "Dominican Republic")
- str.replace("JAM", "Jamaica")
- mapofcodes = {'USA': 'United States of America', ....}
- for word in mystring.split():
- finalstr += mapofcodes.get(word, word)
- import re
- COUNTRIES = {'USA': 'United States of America', 'CAN': 'Canada'}
- def repl(m):
- country_code = m.group(1)
- return COUNTRIES.get(country_code, country_code)
- p = re.compile(r'([A-Z]{3})')
- my_string = p.sub(repl, my_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement