Reputation: 1
Please gently with me as I am beginner. I read the answer for Sorting list of string alphabetically ignoring vowels. But I don't really understand how it sorts in this method:
l = ['alpha', 'beta']
vowels = ['aeiouAEIOU']
sorted(l, key=lambda s: ''.join(c for c in s if c not in vowels))
My questions:
Upvotes: 0
Views: 233
Reputation: 522226
If I understand correctly, you want to sort the strings in your list as if they do not have vowels. So, hello
should sort as hll
and world
should sort as wrld
. You may try removing vowels in your sorting lambda:
l = ['help', 'hello', 'world', 'weld']
l = sorted(l, key=lambda s: re.sub(r'[AEIOUaeiou]', '', s))
print(l) # ['hello', 'help', 'weld', 'world']
Upvotes: 1