Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. str.replace("USA", "United States of America")
  2. str.replace("CAN", "Canada")
  3. str.replace("BHM", "Bahamas")
  4. str.replace("CUB", "Cuba")
  5. str.replace("HAI", "Haiti")
  6. str.replace("DOM", "Dominican Republic")
  7. str.replace("JAM", "Jamaica")
  8.  
  9. mapofcodes = {'USA': 'United States of America', ....}
  10. for word in mystring.split():
  11. finalstr += mapofcodes.get(word, word)
  12.  
  13. import re
  14.  
  15. COUNTRIES = {'USA': 'United States of America', 'CAN': 'Canada'}
  16.  
  17. def repl(m):
  18. country_code = m.group(1)
  19. return COUNTRIES.get(country_code, country_code)
  20.  
  21. p = re.compile(r'([A-Z]{3})')
  22. my_string = p.sub(repl, my_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement