0

Lambda Code Logic

Could anyone let me know what lower() do here? Also how this code sorted the list? https://code.sololearn.com/cyGB02ZHLAFT/?ref=app

21st Nov 2020, 9:21 PM
NIMA
NIMA - avatar
2 Antworten
+ 3
Assume that list have names like ' firstName secondName' so it splitting this name to 2 parts by space then converting last(secondName) one to lower case and this is a key now to sort items.. 'Alf Zed' , 'Mike Mo' , 'Steve Aardvark' This result to by lambda is 'zeb, mo, aradvark' this gets sorted to 'aradvark, mo, zed'.. now it's corresponding original values gets this order..
21st Nov 2020, 9:45 PM
Jayakrishna 🇮🇳
+ 2
Also... the line below is a bit unnecessary: names.sort(key=lambda x: x.split()[-1].lower()) It could be simplified as: names.sort(key=lambda x: x.split()[1]) The .lower() method isn't necessary here and neither is the reverse index.
22nd Nov 2020, 3:17 AM
David Carroll
David Carroll - avatar