+ 1

The 6th python project pls help

This code works well and I passed the code project, but I didn't understand this block"key = len" Why this does this exist? The code: https://code.sololearn.com/cY6u8JRjw7lj/?ref=app

2nd Jul 2022, 7:00 AM
ZIZO Abd alkawy
7 ответов
+ 5
ZIZO Abd alkawy , i am just wondering why you have used a code that you do not understand completely. if you are a bit confused, why not using a basic algorithm that is not difficult to understand: https://code.sololearn.com/cg9NmhEv6N3M/?ref=app
2nd Jul 2022, 11:18 AM
Lothar
Lothar - avatar
+ 3
For example with a list of strings, specifying key=len (the built in len() function) sorts the strings by length, from shortest to longest. The sort calls len() for each string to get the list of proxy length values, and then sorts with those proxy values.
2nd Jul 2022, 7:10 AM
Mihir Lalwani
Mihir Lalwani - avatar
+ 3
2nd Jul 2022, 12:16 PM
ZIZO Abd alkawy
+ 2
max() returns the lexicographically largest value ,the "key" parameter is optional : if you delete it there will not be any errors thelongestword=max(txt.split()) but you will not get the same output as if you want the longest words based on length so we use "key=len"
2nd Jul 2022, 8:31 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
+ 1
I didn't understand it well , I will show the steps that computer should do and correct for me Sample input: hi guys, I am good Take the input The variable should be : input.split=["hi","guys,","I","am","good"] Now the the code should be : max(["hi","guys,","I","am","good"])=guys, And finally print(guys,) The output:guys, Pls correct for me and show me the steps that computer will do Mihir Lalwani
2nd Jul 2022, 8:56 AM
ZIZO Abd alkawy
2nd Jul 2022, 8:57 AM
ZIZO Abd alkawy