Given I have a string list in Python:
list = [" banana ", "Cherry", "apple"]
I want to sort this list to be case insensitive AND ignore the whitespaces. So like this:
list = ["apple", " banana ", "Cherry"]
If I use this:
sorted(list, key=str.casefold)
I get this:
list = [" banana ", "apple", "Cherry"]
It's case insensitive, but the space character comes before the letters.
If I use this:
sorted(list, key=lambda x:x.replace('', ''))
I get this:
list = ["Cherry", "apple", " banana "]
It ignores the spaces but is not case-insensitive. I've tried to combine the two solutions, but I couldn't make it work. Is there a way to fix this easily and "merge" the two results?