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


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/2/3?curriculum_id=4f89dab3d788890003000096#


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


#2

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


#4

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)


#6

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
    else:
        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?


#7

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"
    else:
        print max(a,b)

#8

Pretty unhelpful answer.


#9

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


#10

Hi @jaydacoder, really good point there.

Awesome @designcoder87342

Thank you! :slight_smile:

Benefits of a community.


#11

Why does this run 4 times?


#12

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?


#13

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