The 6th python project pls help | Sololearn: Learn to code for FREE!


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:

7/2/2022 7:00:47 AM

ZIZO Abd alkawy

7 Answers

New Answer


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:


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.


Lothar Mihir Lalwani Get it🙂



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


Mihir Lalwani


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"