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 in Python by Erick
• 120 points
141 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 by Roshni
• 4,630 points

Related Questions In Python

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
346 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
168 views
0 votes
0 answers

Python error "IndexError: list index out of range"

I am trying to execute the following ...READ MORE

Jun 17, 2019 in Python by Alok
6,223 views
+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,452 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,800 points
1,085 views
+1 vote
8 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 in Python by pakainfo
• 200 points
161,656 views
0 votes
1 answer

How to convert each list item into string in a column of data frame. ?

Hey, To split a string you can use ...READ MORE

answered Feb 5 in Python by Roshni
• 4,630 points
168 views