So, I have a list of names, and I'm trying to sort the list such that the names that start with a vowel are positioned first within the list and then those that don't start with a vowel are then positioned after them and sorted alphabetically.
To do this, I wrote the following code, however, the result is not what I expected:
a = ["anna", "ollie", "tim", "bob", "trevor", "susan"]
print(sorted(a, key=lambda x: (x[0] in 'aeiou', x)))
Outcome:
['bob', 'susan', 'tim', 'trevor', 'anna', 'ollie']
I thought based on my code, the names: "anna" and "ollie" should be positioned first, and then the rest of the names since these two names would return true for the first part of my lambda function.
I'd appreciate it if someone can explain why I'm getting this result and what I need to do in order to get my desired outcome.
Thanks!!