list_of_words = ['hoop t','hot op','tho op','ho op t','phot o']
# first sort the words in each string by their length, from longest to shortest
for i, words in enumerate(list_of_words):
list_of_words[i] = sorted(words.split(), key=len, reverse=True)
# second sort the list by how many words there are in each sublist
list_of_words.sort(key=lambda words: len(words)) # sorts list in-place
# third, join the words in each string back together into a single string
for i, words in enumerate(list_of_words):
list_of_words[i] = ' '.join(words)
# show results
print(list_of_words)
如果我正确地理解了你想要实现的目标,这就可以做到:
相关问题 更多 >
编程相关推荐