Skip to content

Instantly share code, notes, and snippets.

@akitotakeki
Created February 4, 2017 08:39
Show Gist options
  • Save akitotakeki/7439578d221ec54011797ec594f92f46 to your computer and use it in GitHub Desktop.
Save akitotakeki/7439578d221ec54011797ec594f92f46 to your computer and use it in GitHub Desktop.
import itertools
list(itertools.permutations('ABCD', 3))
[('A', 'B', 'C'),
('A', 'B', 'D'),
('A', 'C', 'B'),
('A', 'C', 'D'),
('A', 'D', 'B'),
('A', 'D', 'C'),
('B', 'A', 'C'),
('B', 'A', 'D'),
('B', 'C', 'A'),
('B', 'C', 'D'),
('B', 'D', 'A'),
('B', 'D', 'C'),
('C', 'A', 'B'),
('C', 'A', 'D'),
('C', 'B', 'A'),
('C', 'B', 'D'),
('C', 'D', 'A'),
('C', 'D', 'B'),
('D', 'A', 'B'),
('D', 'A', 'C'),
('D', 'B', 'A'),
('D', 'B', 'C'),
('D', 'C', 'A'),
('D', 'C', 'B')]
seq = 'ABCD'
perm = ((x, y, z) for x in seq
for y in seq if y != x
for z in seq if z != x and z != y)
next(perm)
next(perm)
next(perm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment