Advertisement
Guest User

Countries without the letter [X]

a guest
Apr 5th, 2015
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #
  3. # COUNTRIES WITHOUT THE LETTER '[X]'
  4. # In response to a LinkedIn puzzle, "Name a country without the letter A in the name"
  5. # This script reads-in a list of countries, iterates through each letter of the alphabet, and solves for each.
  6. #
  7. # Author: Neil Studd
  8. # URL:    http://www.neilstudd.com
  9.  
  10. import string, urllib, json, operator
  11.  
  12. # For the given letter of the alphabet, output countries which don't contain that letter
  13. def LetterInCountry(letter, countries):
  14.     print "Countries which don't contain " + letter.upper() + ":"
  15.     countries.sort()
  16.     for country in countries:
  17.         if letter.lower() not in country.lower():
  18.             print(country)
  19.     print ""
  20.  
  21. # Load countries from URL
  22. url = "https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/en/country.json"
  23. response = urllib.urlopen(url)
  24. countries = json.loads(response.read())
  25.  
  26. # Loop through alphabet and output a list for each
  27. for letter in string.ascii_lowercase:
  28.     LetterInCountry(letter,countries.values())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement