I have the following list:
List(a, b, c, d, e)
How to create all possible combinations from the above list?
I expect something like:
a ab abc
The unique combination of two lists in Python can be formed by pairing each element of the first list with the elements of the second list. Method 1 : Using permutation() of itertools package and zip() function. Approach : Import itertools package and initialize list_1 and list_2.
Joining queries to find all combinations of two lists Once the queries from the tables are ready, go to Data > Get Data > Combine Queries > Merge to open the Merge dialog of Power Query. Select each table in the drop downs. Click on the column for each table to select them.
Or you could use the subsets
method. You'll have to convert your list to a set first though.
scala> List(1,2,3).toSet[Int].subsets.map(_.toList).toList res9: List[List[Int]] = List(List(), List(1), List(2), List(3), List(1, 2), List(1, 3), List(2, 3), List(1, 2, 3))
def combine(in: List[Char]): Seq[String] = for { len <- 1 to in.length combinations <- in combinations len } yield combinations.mkString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With