我正试图写一个脚本,得到一组字符串-
["ab", "ls", "u"]
然后创建所有可能的组合,但不一定使用所有组合。我希望上述示例的可能输出为:
ab
ab ls
ab ls u
ab u ls
ab u
ls
ls ab
ls ab u
ls u ab
ls u
u
u ls
u ls ab
u ab ls
u ab
我的剧本,去掉了它的其他功能:
stuff = ["ab", "ls", "u"]
for subset in itertools.permutations(stuff):
concat = ""
for part in subset:
concat = concat + part
#the rest of my script now uses this data
它返回:
ablsu
abuls
lsabu
lsuab
uabls
ulsab
我怎样才能让它归还我想要的?你知道吗
你可以同时使用组合和排列。这应该可以让你走了
输出:
你可以处理任何你认为合适的事情
当你给出包含3个元素的列表时,排列将返回包含所有3个元素的结果。 您需要提供1个元素来获得输出中的
ab
/ls
/u
。 您需要提供2个元素来获得输出中的ab ls
/ab u
。你知道吗所以同样的程序可以通过调用列表中的1/2元素来使用。你知道吗
相关问题 更多 >
编程相关推荐