-3

I am trying to achieve the following:

I have two list with the same values.

a = ["A","B","C"]
b = ["A","B","C"]

I want to create pairs by crossing them, but removing identical values as below.

OUT = [("A","B"),("A","C"),("B","C")]

Is there any easy solution?

Thank you very much in advance.

Nikaido
  • 4,443
  • 5
  • 30
  • 47
  • Possible duplicate of [Itertools product without repeating duplicates](https://stackoverflow.com/questions/29314372/itertools-product-without-repeating-duplicates) – Nathan Sep 14 '19 at 15:07

1 Answers1

0

First thing you don't need two lists to group elements. You can directly pass one of the lists to itertools.combinations:

list(combinations(a, 2))

where a is your list.

Example:

from itertools import combinations

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

print(list(combinations(a, 2)))
# [('A', 'B'), ('A', 'C'), ('B', 'C')]
Austin
  • 25,759
  • 4
  • 25
  • 48