# Index out of bound

#1

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

As far as i know , zip method is used when the list have same numbers of elements. Moreover I found index out of bound error in the console.
Any help or code is welcomed.
Thanks

#2

zip can be used with iterables of different length (they might not even have lengths, but still be iterable) - see description of this function by googling python builtins and picking the docs.python.org result

Instead, have you considered the values that you're using to do lookup by index? Those might not be suitable indexes - have you mixed up your values? You're using values that come from using zip, so again you've got reason to read what zip does

#3

thanks @ionatan i have not mixed up the values, i just considered whatever codecademy gave me

#4

It's your code that's crashing isn't it

If you print out a/b - what do you expect them to be?

I still believe you've mixed up values by expecting zip to give you some other values than it does. What you wrote might make sense if zip behaved like you think it does

#5

#6

Look at what your error message says.

There's a crash at line 6.

At line 6, you use a as index for list_a, and you use b as index for list_b
A good guess would therefore be that a isn't a valid index for the list list_a, or that b isn't a valid index for list_b

#7

So how do i validate it?

#8

By understanding what you're asking python to do, and considering what you meant to do. The difference between those two is the change you need to apply.

If you just want to get to next exercise then there's a button in the bottom left to do that

#9

can you just send me the code for this exercise, it'll be really grate help to me, i just need to see what is the coorect code?

#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.