0

I have a list of strings which are some keywords like:

list1 = ["ABC", "DEF", "GHI"]


I want to create a list which merge these together randomly like:

list2= ["ABC" , "DEF" , "GHI" , "ABCDEF", "ABCGHI", ...]

How is it possible?

More info: knowing that itertools.combination module do the job like:

from itertools import combinations
list = ["ABC", "DEF" , "GHI"]
["".join(a) for a in combinations(list, 2)]

will do a combination like:
["ABCDEF", "ABCGHI", "DEFGHI"] but I want all possible answers: which can be done like:

["".join(a) for a in combinations(list, 1)]
["".join(a) for a in combinations(list, 2)]
["".join(a) for a in combinations(list, 3)]

will print:

['ABC', 'DEF', 'GHI']
['ABCDEF', 'ABCGHI', 'DEFGHI']
['ABCDEFGHI']
Heartagramir
  • 344
  • 1
  • 2
  • 9

0 Answers0