I'm trying to sort a list but ignoring a prefix. This question has been answered here. It should be straight forward, only it's not working. Here's what I have:
def sort_it(lst, ignore):
return lst.sort(key=lambda x: x.strip(ignore))
myList = ["cheesewhiz", "www.cheese.com", "www.wagons.com", "www.apples.com", "www.bananas.com"]
ignoreThis = "www."
sort_it(myList, ignoreThis)
print myList
Only the sorting is getting mixed up as the first item doesn't have anything to ignore as part of the string. I'm not sure if adding a check to see if the string contains the ignore string is the Pythonic approach with Lambda.
I expect the results to be in alphabetic order ignoring the www.
www.apples.com
www.bananas.com
www.cheese.com
cheesewhiz
www.wagons.com