Reputation: 107
I have two lists.
one=["first","second"]
two=[1,2]
for o in one:
for t in two:
print(o)
print(t)
and the output is:
first
1
first
2
second
1
second
2
Here is what the correct output should be:
first
1
2
second
1
2
There one more ,my professor has asked to print the output-
first
1
second
2
Upvotes: 0
Views: 422
Reputation: 4469
I think this is what you want:
for o in one:
print(o)
for t in two:
print(t)
So that you only print the string number once per time you run the inner loop.
EDIT:
you can do this:
both = zip(one, two)
for tup in both:
for val in tup:
print(val, end=' ')
Upvotes: 3
Reputation: 3891
Your code should be this:
one=["first","second"]
two=[1,2]
for o in one:
print(o)
for t in two:
print(t)
Upvotes: 2
Reputation: 1603
Just a slight change.
one=["first","second"]
two=[1,2]
for o in one:
print(o)
for t in two:
print(t)
Upvotes: 2