import itertools for i in itertools.permutations('123', 3): print(''.join(i)) 123 132 213 231 312 321