firstString = raw_input("Please enter a String ")
print "This is the sorted ordered " + "".join(sorted(firstString))
secondString = raw_input("please enter a second String ")
print ''.join(sorted(secondString))
thirdString = raw_input("Please enter a third String ")
print ''.join(sorted(thirdString))
fourthString = raw_input("Please enter a fourth String ")
print ''.join(sorted(fourthString))
我输入" Hello World我的名字是John"我得到了" HJWadeehilllmmnnooorsy"
我如何得到这样的结果"你好Wdlor我的aemn是Jhno"
我得到了我想要的结果,如果它只是一个单词,但如果它是一个句子,它只是将所有的音乐结合起来,我该如何添加空格并拥有字母自己整理出来?
答案 0 :(得分:2)
使用split()
字符串函数获取以空格分隔的单词列表。
firstString = raw_input("Please enter a String ")
for word in firstString.split():
print ''.join(sorted(word))
print ' '
答案 1 :(得分:0)
使用此:
print "This is the sorted ordered " + " ".join("".join(sorted(word)) for word in firstString.split())