0

I have few arrays and want to create a bigger_array containing all combination of them, using python. it can have more than two arrays.

But here we take two only.

video4=[1435,1002]  
file_list=['file_1.ts','file_2.ts']

bigger_array=[['file_1.ts', 1435],['file_2.ts', 1002],
              ['file_1.ts', 1002],['file_2.ts', 1435]]
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
SSA
  • 117
  • 4

1 Answers1

2

The output you have show is not a combination, but the product, and the values you are using are python lists, not the arrays.

You can use product from itertools module, it gives a list with tuple of values:

>>> from itertools import product
>>> list(product(file_list, video4))
[('file_1.ts', 1435), ('file_1.ts', 1002), ('file_2.ts', 1435), ('file_2.ts', 1002)]

Intead, if you want list of lists i.e. 2D list, you can convert the tuples to list:

>>> list(map(list,product(file_list, video4)))
[['file_1.ts', 1435], ['file_1.ts', 1002], ['file_2.ts', 1435], ['file_2.ts', 1002]]
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45