我是初学者程序员,在Python 2.7中做一些工作时,我遇到了一个我似乎无法通过的问题。我试图找到所有数字对的所有排列;超出4位数的数组。示例:array = [" a"," b"," c"," d"]我希望看到类似的排列这个:ab,ac,ad,ba,cd,da ...等...到目前为止,这是我的代码,我无法弄清楚下一步:
from itertools import permutations
array = ["a", "b", "c", "d"]
for p in permutations(array):
print(p)
感谢您的帮助,谢谢。
答案 0 :(得分:0)
指定可选参数r,如:
from itertools import permutations
array = ["a", "b", "c", "d"]
for p in permutations(array, r=2):
print(p)