Item1=Item("The Book of Mormon","Joseph smith Jr.",1992 )
Item2=Item("Charlettes web","E.B.White",2013)
Item3=Item("The prince of tides","PatConroy",2004)
Item4=Item("Arise! Awake!","Josephine",1992)
Item5=Item("Wonder","R. J.Palacio",2008)
item_list=[Item1,Item2,Item3,Item4,Item5]
I want to sort the list "item_list" based on the author names. but while sorting i should ignore the special characters. Then the final output should be a list contaning Item2,Item4,Item1,Item3,Item5
You could use a regular expression to create a list containing only the letters (so no special characters are considered) and sort based on that as follows:
This would give you:
The
re.findall('\w'), x)regular expression returns a list of just the characters contained in the author's name, thus removing all of the special characters. So for example the first item would be sorted using a sort key of: