0

I have three files and i want to cross join (or combine) each line of one file with other. EX) File1 contains

a,b,c   

d,e,f

File2 :

1,2,3

4,5,6

so i want output like :

a,b,c,1,2,3

a,b,c,4,5,6

d,e,f,1,2,3

d,e,f,4,5,6

I could do this in python with loops one inside other , but if we have more than 4 files there would be multiple loops .

Is there any other way in python to resolve this in efficient way?

rafaelc
  • 57,686
  • 15
  • 58
  • 82
Himani
  • 41
  • 5
  • Oops, you're looking for the nested iteration (aka cartesian product) of the two files, not the lockstep iteration of them. The answer to that is [`product`](https://docs.python.org/3/library/itertools.html#itertools.product). – abarnert Apr 18 '18 at 04:20
  • 1
    Since you tagged this with `numpy`, you could load each file into an array, join the arrays appropriately, and write a new file. This will be easiest if all data is numeric, but it can also be done with strings. – hpaulj Apr 18 '18 at 04:23

0 Answers0