0
a = [1,2]
b = ["cat", "dog"]
ab = zip(a, b)

for element in ab:
    print(element)

(1, 'cat')
(2, 'dog')

but, I committed an error and wrote this:

for element in ab:
    print(ab)

then I wrote:

for element in ab:
    print(element)

that did not print any output, so my question is, basically, why?

Charge
  • 11
  • 2

1 Answers1

0

This is because a and b are of type list, whereas ab is a zip object so doesn't behave in the same way. Try converting ab to a list

AB = list(ab)
print(AB)
Emi OB
  • 2,814
  • 3
  • 13
  • 29