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

26th Jan 2021, 4:15 AM
sihle bavu
sihle bavu - avatar
2 Answers
+ 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]
26th Jan 2021, 4:24 AM
visph
visph - avatar
+ 1
where is your attempt ?? you can use max() func : 👇👇 print(max(input().split(),key=len)) https://code.sololearn.com/cA1XPvTLSp1j/?ref=app
26th Jan 2021, 5:09 AM
Ratnapal Shende
Ratnapal Shende - avatar