+ 2
How to print sorted string in python ?
Like Sample I/p: I love to code Sample o/p: code I love to
56 Respostas
+ 5
def fun(x):
return x.lower()
a = input().split()
a.sort(key = fun)
ans = ' '.join(a)
print(ans)
+ 2
It works...
But maybe the prob is that not all words are lowercase
I love to code // i love to code
+ 2
Better still, post your code so we can know how to really help you out.
+ 2
1)msg=str(input()).split()
2)msg.sort()
3)print(' '.join(msg))
+ 2
.strip() remove characters from both left and right based on the argument..
+ 2
Mr.Gaurav urs is also correct, there r multiple ways in answering a problem
+ 2
https://www.google.com/amp/s/www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-string-strip-2/amp/
This might help for those who need the use of strip ()
+ 2
This is good. Moe Kyaw Oo. Using a function as the sort key....OMG. That is neat!
+ 1
Neglect the upper and lower case in this,
+ 1
No
+ 1
n = input()
l = sorted(n.split(), key=lambda x: x.lower())
print(l[0], l[-1])
# or
mystring = l[0] + ' ' + l[-1]
print(mystring)
+ 1
I always go to youtube, geeksforgeeks or stackoverflow then see if my question has already been solved. I found a youtube video for you because I think it would benefit you if you know how strings work in general in python. https://youtu.be/UsCQXe1OHZk
+ 1
No use, just see my code. It's perfectly working Ramya Thiurmalisamy
+ 1
But i dont think here .strip() is needed. Just check out my code sai kumar
+ 1
I think question is self explanatory. You have given a string and you have to sort the string on the basis of it's words i.e Lexicographically
e.g (1)
Input - are you ok
Output - are ok you
e.g (2)
Input - This is important
Output - important is This
+ 1
Tomiwa Joseph bro you will never get what I want to say. Just go through my code and see what the outcome is when you input "This is important" is returned as "important is This"
+ 1
This will surely work Moe Kyaw Oo
0
What have you tried already my man?
0
I tried the following,but not passed,i think it's wrong,I searched the solution but not found the clear one
n=input()
k=sorted(n.split())
l=' '.join(k)
Print(l)