【题目描述】
求输入的句子中字母的顺序排列组合
【输入】
一段不知道长度以空格分隔的英文句子
【输出】
以list输出所有组合
【输入样例】
how are you
【输出样例】
[hay, hao, hau, hry, hro, hru, hey, heo, heu,
oay, oao, oau, ory, oro, oru, oey, oeo, oeu,
way, wao, wau, wry, wro, wru, wey, weo, weu]
推荐看一下笛卡尔积
import itertools
def func(mes):
mes_list = mes.split(' ')
mes_list = iter(list(i) for i in mes_list)
yet = []
for i in itertools.product(*mes_list):
i = "".join(itertools.chain(*i))
yet.append(i)
return yet
mes = 'how are you'
print(func(mes))