+ 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
7 Réponses
+ 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
+ 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.
+ 3
Lothar
Mihir Lalwani
Get it🙂
+ 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"
+ 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