Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #
- # COUNTRIES WITHOUT THE LETTER '[X]'
- # In response to a LinkedIn puzzle, "Name a country without the letter A in the name"
- # This script reads-in a list of countries, iterates through each letter of the alphabet, and solves for each.
- #
- # Author: Neil Studd
- # URL: http://www.neilstudd.com
- import string, urllib, json, operator
- # For the given letter of the alphabet, output countries which don't contain that letter
- def LetterInCountry(letter, countries):
- print "Countries which don't contain " + letter.upper() + ":"
- countries.sort()
- for country in countries:
- if letter.lower() not in country.lower():
- print(country)
- print ""
- # Load countries from URL
- url = "https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/en/country.json"
- response = urllib.urlopen(url)
- countries = json.loads(response.read())
- # Loop through alphabet and output a list for each
- for letter in string.ascii_lowercase:
- LetterInCountry(letter,countries.values())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement