aubaldor
aubaldor

Reputation: 33

How can I "alternate" display the content of two lists?

Im trying to achieve being able to display the content of two lists displayed in the following way or at least something similar to the following:

list_1 = [price1, price2, price3, price_n]

list_2 = [concept1, concept2, concept3, concept_n]

And when printed I want to display that info like this:

price1

concept1

price2 

concept2

(you get the idea)

Im using a a "for" loop, however, im not sure how to include the second list for it to be displayed like that on the same "for" or how can achieve this?

Thanks for any feedback provided.

Upvotes: 1

Views: 67

Answers (2)

Hasibul Islam Polok
Hasibul Islam Polok

Reputation: 105

list_1 = ['price1', 'price2', 'price3', 'price_n']

list_2 = ['concept1', 'concept2', 'concept3', 'concept_n']

for i in range(len(list_2)):
    print(list_1[i],list_2[i])

Are you looking for this?

Upvotes: 1

jfaccioni
jfaccioni

Reputation: 7509

the function zip is specifically made for this - iterate through two sequences side-by-side:

for price, concept in zip(list_1, list_2):
    print(price)
    print(concept)

Upvotes: 3

Related Questions