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 24, 2020 in Python by Erick
• 120 points
6,328 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 24, 2020 by Roshni
• 10,420 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,780 points
508 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
251 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,840 views
0 votes
0 answers
+4 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,810 points
1,419 views
+1 vote
10 answers

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

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17, 2020 in Python by pakainfo
• 200 points
228,387 views
0 votes
4 answers

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

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

answered Dec 15, 2020 in Python by Roshni
• 10,420 points
42,612 views