-1

How do I create a cartesian product of a list itself with unique elements?

For example, lists = ['a', 'b', 'c'], and I want to create [['a', 'b'], ['a','c'], ['b','c']].

martineau
  • 119,623
  • 25
  • 170
  • 301
Berlin Bolin
  • 77
  • 1
  • 7

1 Answers1

1
from itertools import combinations
lists = ['a', 'b', 'c']
print(list(map(list, combinations(lists,2))))
Bing Wang
  • 1,548
  • 1
  • 8
  • 7