Last active
January 1, 2016 15:49
-
-
Save dmpeters/8166620 to your computer and use it in GitHub Desktop.
thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def formater_a(city): | |
pos1 = city.find('(') - 1 # finds the position of the first parenthese and substracts 1 | |
pos2 = city.find(')') - 2 # finds the position of the second parenthese and substracts 2 (assumes the the final 3 characters are a state abbreviation with a closing parenthese) | |
return '{0}, {1}'.format(city[:pos1], city[pos2:-1]) # returns a formated string of the city by slicing | |
def formater_b(city): | |
return city.replace(',', '').replace(' ', '-').lower() # returns a formated string of the city by removing any commas and replacing any empty spaces with dashes | |
z = ['Del Mar (San Diego, CA)', 'Alamo, CA'] | |
for city in z: | |
if city.find('('): | |
formater_b(formater_a(city)) | |
else: | |
formater_b(city) | |
print city |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
formater_a converts "Del Mar (San Diego, CA)" to "Del Mar, CA"
formater_b converts "Del Mar, CA" to "del-mar-ca"