how to solve this IndexError list index out of range in python and streamlit

0 votes

In this recommend system, if I define the variable item_id as 4 (for example) it will work perfectly. But if I use this:

item_id = int(st.number_input('Digite a id do livro:'))

... it will not work and will give me IndexError: list index out of range

even I use input instead of st.number_input it will work in the terminal.

Sep 25, 2020 in Python by Erick
• 120 points
25,426 views

1 answer to this question.

0 votes

Hi,  @Erick,

To solve the “index error: list index out of range” error, you should make sure that you’re not trying to access a non-existent item in a list.

If you are using a loop to access an item, make sure that the loop accounts for the fact that lists are indexed from zero. If that does not solve the problem, check to make sure that you are using range() to access each item by its index value.

answered Sep 25, 2020 by Roshni
• 10,520 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
1,231 views
–1 vote
2 answers
0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14, 2019 in Python by Junaid
855 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,009 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
2,207 views
+1 vote
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
370,565 views
0 votes
4 answers

How to print objects of class using print function in Python?

>>> class Test: ... ...READ MORE

answered Dec 16, 2020 in Python by Roshni
• 10,520 points
68,305 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP