looping through two list simultenously

jim-on-linux inq1ltd at verizon.net
Sun Oct 29 19:02:02 EST 2006


On Sunday 29 October 2006 15:28, CSUIDL PROGRAMMEr 
wrote:
> folks
> I have two lists
>
>  i am trying to loop thorough them
> simultenously.
>

Try something like this.

 for eachline in data1:
     print eachline
     for line in data::
         print line

You might also think about a while loop.

jim-on-linux

http://www.inqvista.com



> Here is the code i am using
>
> f1 = os.popen('ls  chatlog*.out')
> data1=f1.readlines()
> f1.close()
>
> data1=[x.strip() for x in data1]
> f1 = os.popen('ls  chatlog*.txt')
> data=f1.readlines()
> f1.close()
> for eachline in data1 and line in data:
>
>     filename='/root/Desktop/project/'+ eachline
>     print filename
>     outfile=open(filename,'r')
>     filename1='/root/Desktop/project/' + line
>     print filename1
>
> I get the error that line is not defined.
> Traceback (most recent call last):
>   File "list.py", line 16, in ?
>     for eachline in data1 and line in data:
> NameError: name 'line' is not defined
>
> Is there any efficient doing this



More information about the Python-list mailing list