-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
  • 112,593
  • 23
  • 157
  • 280
Berlin Bolin
  • 67
  • 1
  • 6

1 Answers1

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