Jul-28-2019, 06:28 PM
Hello everyone,
I need your help about the script below.
Originally, I wanted to have all datas product from 4 text files inputs. Each text file contains from 20 to 55 lines.
The script below works as intended but now, I would like them to be saved in a text file.
I tried different ways, but I can't find a solution by myself.
I still have trouble understanding how to structure the record in a file. I specify that I don't need the different combinations appears in the editor, only in the output text file.
Can anyone provide me some help/advice ?
Thanks
I need your help about the script below.
Originally, I wanted to have all datas product from 4 text files inputs. Each text file contains from 20 to 55 lines.
The script below works as intended but now, I would like them to be saved in a text file.
I tried different ways, but I can't find a solution by myself.
I still have trouble understanding how to structure the record in a file. I specify that I don't need the different combinations appears in the editor, only in the output text file.
Can anyone provide me some help/advice ?
Thanks
1 2 3 4 5 6 7 |
import fileinput from itertools import product from contextlib import closing with closing(fileinput. input ([ 'wood.txt' , 'color.txt' , 'year.txt' , 'quality.txt' ])) as f: for w, x, y, z in product(f, repeat = 4 ): print '{}-{}-{}-{}' . format (w.rstrip( '\n' ),x.rstrip( '\n' ), y.rstrip( '\n' ), z.rstrip( '\n' )) |