Multiple Lists


#1



I'm stuck at "Multiple lists" in the loops section.


The Instructions say:
"Compare each pair of elements and print the larger of the two."
and they give me the code that is commented below.

So I wrote this.
But it doesn't work !


"""
list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]

for a, b in zip(list_a, list_b):
    # Add your code here!
"""

list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]

for a, b in zip(list_a, list_b):
    # Add your code here!
    if(len(list_a)>len(list_b)):
        print list_b
    else:
        print list_a


But it doesn't work !


#2

elements means elements in the list, so have to compare 3 and 2, 9 and 4, 17 and 8. (compare the actual values inside the list with each other)


#3

Now I've written this, but it still doesn't work

list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]

for a, b in zip(list_a, list_b):
    # Add your code here!
        if(list_a[a]>list_b[b]):
            print list_a[a]
        else:
            print list_b[b]

It says "IndexError: list index out of range"
How can I fix that ?


#4

Okay, I have already fixed it.
But thanks anyway !


#5