from itertools import permutations input = ('s', 't', 'u', 'f', 'f') length = 2 for p in permutations(input, r=length): print(p)
Standard input is empty
('s', 't')
('s', 'u')
('s', 'f')
('s', 'f')
('t', 's')
('t', 'u')
('t', 'f')
('t', 'f')
('u', 's')
('u', 't')
('u', 'f')
('u', 'f')
('f', 's')
('f', 't')
('f', 'u')
('f', 'f')
('f', 's')
('f', 't')
('f', 'u')
('f', 'f')