过滤排列
Filtering a permutation
我是一名初级程序员,在 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)
如果能得到任何帮助,我将不胜感激,谢谢。
指定可选参数 r,如:
from itertools import permutations
array = ["a", "b", "c", "d"]
for p in permutations(array, r=2):
print(p)
我是一名初级程序员,在 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)
如果能得到任何帮助,我将不胜感激,谢谢。
指定可选参数 r,如:
from itertools import permutations
array = ["a", "b", "c", "d"]
for p in permutations(array, r=2):
print(p)