How to sort words in a string with Python

2 Answers

0 votes
s = "python c++ java php c#"

words = s.split()

words.sort()

for word in words:
    print(word)


'''
run:
 
c#
c++
java
php
python
 
'''

 



answered Jun 18, 2017 by avibootz
0 votes
s = "python c++ java php c#"

words = s.split()

words.sort()

s = ""
for word in words:
    s = s + word + ' '

s = s.strip()

print(s)


'''
run:
 
c# c++ java php python
 
'''

 



answered Jun 18, 2017 by avibootz
...