0
How do you compare the length of a string in a list with another string in a list?
I am trying to find the longest word in a list of strings, the code accepts input from the user, converts that input into a list of strings, then outputs the longest word from that list
2 Respuestas
+ 1
words = ["abc","defgh","ijk","lmn","opqrst","uvw","xyz"]
length = [len(s) for s in words]
max_len = max(length)
max_words = [s for s in words if len(s) == max_len]
+ 1
where is your attempt ??
you can use max() func : 👇👇
print(max(input().split(),key=len))
https://code.sololearn.com/cA1XPvTLSp1j/?ref=app