def comb(L): if len(L) <= 1: return [L] c = [] for i in range(len(L)): for k in comb(L[:i] + L[i + 1:]): c.append([L[i]] + k) return c print(comb([1, 2, 3]))
Standard input is empty
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!