Last active
May 5, 2020 21:40
-
-
Save DHS/dc5114829e42bbe4b550e0099c8eb091 to your computer and use it in GitHub Desktop.
My solution for https://github.com/DHS/vowellator
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
# 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