0

Sorting

how can we sort using second string in a set of list. list1=["willy","Cooper","Ram","hell"] out put should be based on second letter of each word i.e I, o, a, e list1=["Ram","hell","willy","Cooper"]

22nd May 2018, 10:12 PM
Kesava N
Kesava N - avatar
3 odpowiedzi
+ 4
Write whatever sort you like and instead of comparing first > second use first[1:] > second[1:]. string[1:] creates a substring of the second character to the end.
22nd May 2018, 10:31 PM
John Wells
John Wells - avatar
+ 2
A sort must compare the strings. I'm telling you how to ignore the first character when you do your compare.
22nd May 2018, 10:35 PM
John Wells
John Wells - avatar
0
didn't get u. r u asking me to compare a string?
22nd May 2018, 10:33 PM
Kesava N
Kesava N - avatar