16.Multiple Lists Help me out of this..?!



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 a(list_a) > b(list_b):
        print a(list_a)
        print b(list_b)


a and b hold the lists, you can just compare them. Not sure what a(list_a) is suppose to be


To compare each pair of elements and print the larger of the two, you could do the below although your code should work fine:

print max(a, b)


I agree with bayoishola20 . The less code is better, but what if the values at the index position were the same? I believe it would be best to use the other method. For example...

list_a = [3, 1, 17, 15, 30]
list_b = [2, 4, 8, 99, 30, 40, 50, 60, 70, 80, 90]

for a, b in zip(list_a, list_b):
    if a > b:
        print a
    elif a < b:
        print b
        print "Numbers are the same"

Also, list_b has more index items than list_a. Is there a way to print these in the same code?


That's a good point about the possibility of equal values, in which case, neither is "larger", strictly speaking. So combining the suggestions of the two solutions above, you could address this a little more succinctly like this:

for a, b in zip(list_a, list_b):
    if a == b:
        print "Values are equal, so neither is larger"
        print max(a,b)


Pretty unhelpful answer.


no, why? a and b holds the items in the lists in turn, and then you can just compare a and b. Yes, there is some thinking left to do, since you have to remove the function calls.

Saying an answer is unhelpful is also not very helpful, at least then tell why the answer is unhelpful


Hi @jaydacoder, really good point there.

Awesome @designcoder87342

Thank you! :slight_smile:

Benefits of a community.


Why does this run 4 times?


You simply repeated the question. "...you can just compare them." Someone asks a teacher "How do I compare lists?" and the teacher says, "You can just do it." Good teacher or bad teacher?


maybe not my best answer, but the second explanation is better_emphasized text_