0

Why am I not able to sort the resultant list??

def func(str): return len(str) a = input("Enter:").split(" ") p = list(zip(a,list(map(func,a)))) p.sort(reverse=False) print(p)

12th Jan 2022, 10:36 AM
Ravi King
7 Respostas
+ 1
In that case your code is much more complicated than needed. You can just take an input, make it a list, and print out the longest word (using the max() function), and the length of it (so you will need len(max(input))). Try that and I'll help if you need it
12th Jan 2022, 11:18 AM
Kamil Hamid
Kamil Hamid - avatar
+ 1
Solomoni Railoa that is a good way of doing it, however I believe that it can be simplified further. Here is the link to my explanation through it: https://code.sololearn.com/cYAnMGomH9VJ And yes it is possible to take out the quotation marks but it is very long and unnecessary
12th Jan 2022, 1:34 PM
Kamil Hamid
Kamil Hamid - avatar
0
It is sorting correctly. Maybe it's not sorting as you want, how do you want it to sort?
12th Jan 2022, 10:45 AM
Kamil Hamid
Kamil Hamid - avatar
0
Here's the task: I will enter a sentence and i need to return the max length in it along with the word Ex: Input: "I love programming" Output: (Programming,11)
12th Jan 2022, 11:10 AM
Ravi King
0
Thank you 😀
12th Jan 2022, 3:21 PM
Kamil Hamid
Kamil Hamid - avatar