Эта проблема настроена для itertools
, например ::1002 *
In []:
import itertools as it
n = 4
choices = ['James']*n + ['Pauline', 'Sarah', 'Benedict', 'Phillippa', 'John']
list(it.combinations(choices, r=n))
Out[]:
[('James', 'James', 'James', 'James'),
('James', 'James', 'James', 'Pauline'),
('James', 'James', 'James', 'Sarah'),
('James', 'James', 'James', 'Benedict'),
...
('Pauline', 'Sarah', 'Benedict', 'John'),
('Pauline', 'Sarah', 'Phillippa', 'John'),
('Pauline', 'Benedict', 'Phillippa', 'John'),
('Sarah', 'Benedict', 'Phillippa', 'John')]
Но по вашему примеру трудно сказать, возможно, вы ищете permutations
:
In []:
list(it.permutations(choices, r=n))
Out[]:
[('James', 'James', 'James', 'James'),
('James', 'James', 'James', 'Pauline'),
('James', 'James', 'James', 'Sarah'),
('James', 'James', 'James', 'Benedict'),
...
('James', 'John', 'Benedict', 'James'),
('James', 'John', 'Benedict', 'James'),
('James', 'John', 'Benedict', 'James'),
('James', 'John', 'Benedict', 'Pauline'),
...]