Skip to content

Instantly share code, notes, and snippets.

@DHS
Last active May 5, 2020 21:40
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 DHS/dc5114829e42bbe4b550e0099c8eb091 to your computer and use it in GitHub Desktop.
Save DHS/dc5114829e42bbe4b550e0099c8eb091 to your computer and use it in GitHub Desktop.
# My solution for https://github.com/DHS/vowellator
# Assumptions
#
# No names contain spaces
# All names contain vowels
# Names with same first vowel should be returned in same order as inputted
# Additional test cases
#
# ("bond hall squire smith legge", "hall legge smith bond squire"), # every vowel
# ("edwards aldrich toller hall", "aldrich hall edwards toller"), # multiple a
# ("toller edwards", "edwards toller"), # without an a
def vowellate(names_input=None):
# Can haz vowels
vowels = ['a', 'e', 'i', 'o', 'u']
# Set up a dict of lists
names = {}
for vowel in vowels:
names[vowel] = []
# Loop through list spotting vowels and add to appropriate list
for name in names_input.split():
for letter in name:
if letter in vowels:
# print('Found a vowel: ' + letter)
names[letter].append(name)
break
# Inspect our glorious creation
# print(names)
names_output = ''
for vowel in vowels:
if names[vowel]:
# I don't love this
names_output += ' ' + ' '.join(names[vowel])
return names_output[1:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment