Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
finditer()'s span() solution in Clear category for Combining Celebrity Names by kkkkk
import re
def find_vowel_indices(name: str) -> dict:
"""Return list of indices for locations of vowel groups in name."""
# This could be a list comprehension, but it was easier debugging
# it when the 'for' loope was not compressed.
vowel_groups = []
for match in re.finditer(r"([aeiou]+)", name):
vowel_groups.append(match.span()[0])
return vowel_groups
def brangelina(first: str, second: str) -> str:
"""Combine two names to create a catchy shorthand for name pair."""
catchy_name = []
first_vowels = find_vowel_indices(first)
if len(first_vowels) == 1:
catchy_name.append(first[:first_vowels[0]])
else:
catchy_name.append(first[:first_vowels[-2]])
second_vowels = find_vowel_indices(second)
catchy_name.append(second[second_vowels[0]:])
return "".join(catchy_name)
Sept. 17, 2023