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))
+ 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 :)
+ 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!
+ 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.
+ 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
+ 1
I added all your codes to my code as comment. Thanks again DavX
It was good job!
+ 1
Okay thanks
+ 1
https://code.sololearn.com/c016tI8pPE65/?ref=app
Code in java
0
Post your code
0
Please, firstly show your attempt. After that, specify your problem clearly. Thanks!
Happy coding!
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
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 :)