0
Longest word in a list in python
I cleared two test cases not sure about the 3 and 4 https://code.sololearn.com/cytB1eo0hahR/?ref=app
2 Respostas
+ 3
Your code will automatically print the second element in the list (eventhough it is not the longest string) because of the condition "if lst[0] != max" This will be always True on second iteration:
To fix:
-> set the first element of the lst as default "max".
max = lst[0]
-> change the max if it is longer than the previous one.
-> print max outside loop or after iteration.
If you need more explanation, please feel free to ask. Thanks!
https://code.sololearn.com/cA8A15A6A4A1
+ 1
Thanks bro now I understand : )