Advertisement
Guest User

exercise for dicts

a guest
Nov 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. __author__ = 'Zaineb Chouhdry'
  2. file = open("rawdata.txt", mode="r", encoding="utf8")
  3.  
  4. countryIncomes = dict()
  5. countrySets = dict()
  6.  
  7. ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  8.  
  9. for letter in ascii_uppercase:
  10. countrySets[letter] = []
  11.  
  12. for line in file:
  13. info = line.split(":")
  14. index = info[0]
  15. country = info[1].replace("\n", "")
  16. income = info[2].replace("\n", "")
  17.  
  18. countryIncomes[country.upper()] = income
  19.  
  20. firstLetter = country.upper()[0]
  21. countrySets[firstLetter].append(country.upper())
  22.  
  23. while True:
  24. user_input = input("Enter an initial or a country name: ").upper()
  25.  
  26. if user_input == "QUIT":
  27. break
  28.  
  29. if len(user_input) == 1: #initial
  30. print(countrySets[user_input])
  31. elif len(user_input) > 1: #possibly country name
  32. if user_input in countryIncomes:
  33. print(countryIncomes[user_input])
  34. else:
  35. print("Does not exist")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement