0

I have a list

a = ['A', 'B', 'C']

and from that list, How to get all the 2 by 2 combinations? Like this:

A, B
A, C
B, A
B, C
C, A
C, B

1 Answers1

0

Use itertools.permutations:

>>> from itertools import permutations
>>> a = ['A', 'B', 'C']
>>> list(permutations(a,2)) # see second argument which specifies permutation length 
[('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]
Vicrobot
  • 3,795
  • 1
  • 17
  • 31