如何从字符串中生成python 3 itertools product / combinations / permutations

时间:2015-10-30 18:00:34

标签: python itertools

  

嗨!   我想在python 3.4中制作混合字符串程序。像输入:string1 = 123,string2 = abc,string3 = 4g6。输出应该像string1,2和3的组合。例如:1234g6abc。我尝试在itertools中搜索,只有字母组合而不是单词。我想要言语。请帮忙。">

2 个答案:

答案 0 :(得分:0)

将字符串添加到列表中,使用https://developer.github.com/v3/pulls/,然后加入结果。

import itertools

L = [string1, string2, string3]
# Convert perms to list if you want to iterate multiple times
perms = itertools.permutations(L)
for perm in perms:
    print(''.join(perm))

答案 1 :(得分:0)

import itertools as it

>>> list(map(''.join,list(it.permutations(['234','g6','abc']))))

['234g6abc', '234abcg6', 'g6234abc', 'g6abc234', 'abc234g6', 'abcg6234']