In a python script I have 2 files printing side by side on the same line. I want to have 1 of the files to be already displayed at once while the other file print down the list in the file and it still will produce new lines. I want to do it like that to reduce printing a lot of lines and combinations.
from itertools import izip_longest
with open("file1") as textfile1, open("file2") as textfile2:
for x, y in izip_longest(textfile1, textfile2, fillvalue=""):
x = x.strip()
y = y.strip()
print("{0}{1}".format(x, y))
This is what the script does now:
aaaaaa 111111
bbbbbb 222222
cccccc 333333 Both lines move and still print
the same lines every time.
dddddd 444444
eeeeee 555555
gggggg 666666
What I desire the script to do:
This file2 is
about to go
through file1
111111 This will print first in the order of the file
222222 second
333333 third
444444 fourth
555555 fifth
666666 This will print last in the order of the file
↓↓
This file1
is already
loaded or
displayed
at once
not moving
at all
aaaaaa
bbbbbb As file2 goes down file1, each line
should hit every line creating a new
cccccc combination until the list has completely
went through.
dddddd
eeeeee
gggggg
file2 is done going
through file1
111111
222222
333333
444444
555555
666666
111111 should hit aaaaaa first,
then when 111111 will hit bbbbbb,
222222 should be on aaaaaa,
then when 111111 hit cccccc,
2222222 should be on bbbbbb,
then 333333 should be on aaaaaa, then so on and so on.
The list should go down the other list in a trail line until completely.
Example of output
Example of output or what I should see in terminal
aaaaaa
bbbbbb 666666
cccccc 555555
dddddd 444444
eeeeee 333333 Each line is trailing down the list
gggggg 222222
111111