Created
April 10, 2020 17:25
-
-
Save klahrich/1452db9fbfd3b36da9c588d559c1429c to your computer and use it in GitHub Desktop.
This file contains 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
# Challenge no 2: you have a list of names, and you want to find out which names are both long AND have a high percentage of vowels in them. | |
names = ['Maria', 'Leila', 'Karim', 'Jon', "Kalimero", "John", "Armstrong", "Braztchniev", "Mougandae"] | |
name_lengths = [len(w) for w in names] | |
relative_lengths = [l / max(lengths) for l in name_lengths] | |
vowel_counts = [sum([Counter(name)[v] for v in "aoeui"]) for name in names] | |
vowel_perc = [vc / l for vc, l in zip(vowel_counts, name_lengths)] | |
sorted(zip(names, relative_lengths, vowel_perc), key=lambda t: 2*t[1]*t[2] / (t[1] + t[2]), reverse=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment