可能重複:
Power set and Cartesian Product of a set python的Python itertools排列如何包括重複字符
使用Python和itertools.permutations()我想與重複字符接收並輸出置換。例如,下面我的函數和它的當前輸出。
def perm(n,i):
b = 0
while b < n:
n= n -1
from itertools import permutations as p
file.write('\n'.join([''.join(item) for item in p(i,n)]))
perm(4,'0123')
輸出爲:
012
013
021
023
031
032
102
103
120
123
130
132
201
203
210
213
230
231
301
302
310
312
320
321.....
我怎麼會得到像112或222的輸出?
從我所瞭解的組合不是順序排列的位置。我正在尋找的是找到所有組合,然後每個組合的每個排列組合。這可能嗎?
爲什麼每次在循環中導入'permutations'?爲什麼'''延長線?你可以至少清理一下.. –