Issue
For starters i did this
text = "Hello I want to make this code better"
x = text.split()
sorted_characters = sorted(x[5])
sortedword = "".join(sorted_characters)
print(sortedword)
I want the code to do this but i couldn't figure out how to seperate words and every string in list:
example=['I like python', 'I like reading books']
Output should be ['I eikl hnopty', 'I eikl adeginp bkoos']
Solution
A one liner:
[' '.join([''.join(sorted(z)) for z in i.split()]) for i in example]
This just does what you did, with the list comprehension feature of python, and sort every element in the list
Answered By - Idan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.