以下是一个示例函数,它接受一个句子作为输入,并输出一个排序后的句子:
def sort_sentence(sentence):
# 将句子拆分为单词列表
words = sentence.split()
# 对单词列表进行排序
sorted_words = sorted(words)
# 将排序后的单词列表重新组合成句子
sorted_sentence = ' '.join(sorted_words)
return sorted_sentence
# 测试函数
sentence = "This is a sample sentence"
sorted_sentence = sort_sentence(sentence)
print(sorted_sentence)
输出结果为:"a is sample sentence This"