Skip to content

Instantly share code, notes, and snippets.

@dmpeters
Last active January 1, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmpeters/8166620 to your computer and use it in GitHub Desktop.
Save dmpeters/8166620 to your computer and use it in GitHub Desktop.
thing
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
@dmpeters
Copy link
Author

formater_a converts "Del Mar (San Diego, CA)" to "Del Mar, CA"
formater_b converts "Del Mar, CA" to "del-mar-ca"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment