0

I have two lists which contain titles and links to interesting pages (trying to write a scraper).

Where I'm falling down is on the actual printing.

for i in var1:
    print i

for a in var2:
    print a

Prints all of list 1 and then all of list 2. If I try this

for i in var1:
    print i
    for a in var2:
        print a

I get one of var1 printed, then 10 of var2 this continues till end of list.

How can I get python to print 1 line from list 1, 1 line from list 2 and then continue till the lists are finished?

THank you in advance.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by yeleek
1

Use zip

for i, a in zip(var1, var2):
    print i
    print a

Items are printed until the shortest list is consumed.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.