for loop for two lists

Hi

  I would like to make permutation of two lists in python. 

for example: 

first file  contains (file1)

1

2

3

second file contains (called file2)

a

b

c

The output of the permutation should be 

 

1 a

1 b

1 c

2 a

2 b

2 c

3 a

3 b

3c 

in python: 

 for i in file1:

     for j in file2:

         print i.rstrip(), j.rstrip 

But the output is only

1 a

1 b

1 c

Could some  suggest what I am missing, or what is other way in python to do this

 Psan

 

 

 

 

 




Leave comments

authimage
  • try this:
    [(a,b) for a in [1,2,3] for b in ['a', 'b', 'c']]

    • hulala
  • Try to reopen file2 file each file1 iteration or store it's results in local variable before.

    • Varela
  • try this:

    x = zip(list_one, list_two)

    • Danillo Souza
  • Did this work after?


Copyright(c) 2017 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved