Index out of bound


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!
print list_a[a]
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.


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 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


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


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

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


Here is all I can show you, please help me out!


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


So how do i validate it?


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


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?


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