Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
Your welcome, you could refine to two lines: words = input().split(' ') print(max(words, key=len))
14th Sep 2021, 8:48 PM
DavX
DavX - avatar
+ 4
Sorry for the long code! I wrote it now and don't have time to make it shorter: a = 'this is awsome' b = a.split() v=[] for i in range(len(b)): s = len(b[i]) v.append(s) e = max(v) for i in range(len(b)): if len(b[i])==e: print(b[i]) Hope u like python :)
14th Sep 2021, 9:40 PM
Amirreza
Amirreza - avatar
+ 4
Calvin Thomas I wouldn’t take it personally. It looks like all of the comments have been downvoted! Although as a guess, yours was probably downvoted due to the length, and the bit “without using any built in functions, apart from these three!!” did make me chuckle :D Honestly though don’t take it personally, I’ve just gone on a rampage upvoting your posts! Hope this helps, keep smiling!
15th Sep 2021, 11:23 AM
DavX
DavX - avatar
+ 3
mesarthim Nice! Although did you know that you can avoid sorting the list? If you replace ‘sorted’ with ‘max’ like so: longest = max(newstr, key = len) Your variable then contains just the longest word. When printing no need to reference the last element.
14th Sep 2021, 8:42 PM
DavX
DavX - avatar
+ 2
Calvin Thomas hi I don't think if your code gives the true output For example for : wow its awesome will give (wow) as output
15th Sep 2021, 12:29 PM
Amirreza
Amirreza - avatar
+ 1
I added all your codes to my code as comment. Thanks again DavX It was good job!
14th Sep 2021, 8:55 PM
mesarthim
mesarthim - avatar
+ 1
Okay thanks
15th Sep 2021, 1:04 PM
Odonghanro Faith
Odonghanro Faith - avatar
16th Sep 2021, 6:48 AM
darwin j mathews
darwin j mathews - avatar
0
Post your code
14th Sep 2021, 7:29 PM
Atul [Inactive]
0
Please, firstly show your attempt. After that, specify your problem clearly. Thanks! Happy coding!
14th Sep 2021, 7:57 PM
mesarthim
mesarthim - avatar
0
You can use these steps: 1- Take an input as string 2- Seperate the words in the given string 3- Sort the words 4- Print the longest word Also, you can check my code. Happy coding! https://code.sololearn.com/cBYd2kS82S6i/?ref=app
14th Sep 2021, 8:17 PM
mesarthim
mesarthim - avatar
0
It's amazing! That's a good solution. While I was solving the problem, I couldn't think this point. Thanks a lot DavX :)
14th Sep 2021, 8:47 PM
mesarthim
mesarthim - avatar