Please explain how " rocket " is on index 1 and "plane" on index 4 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please explain how " rocket " is on index 1 and "plane" on index 4

m=["car","plane","train","bike","rocket"] n=sorted (m, key=lambda x: x[-2]) print(n)

14th May 2020, 3:10 PM
Navneet
Navneet - avatar
1 Answer
+ 1
The lambda specifies that the items in list <m> are to be sorted by the second to last character of the items. car -> a rocket -> e train -> i bike -> k plane -> n See? the items are sorted by the second to the last character.
14th May 2020, 5:20 PM
Ipang