Value error: 1 while trying to acces list item

mir = collectlist[10] #there are 12 items in collectlist
mon = collectlist[0]

for value in currentlist:
mon=mon[row] #total of 94 rows in mon, mon[[0] is first row
mir=mir[row] <–value error !!!
row += 1

mir gives me a value error starting on the first row, I’ve checked if row 0 excists and it does. So I’m not sure why mon doesn’t give a value error but mir does. When I just use mir or just use mon it works but when I use both variables, mir gives me a value error.

Does anyone have an idea what is going on here ?

Thanks in advance !strong text

Simple question - what is row and does it exists?

Print out the value of mir and mon to see what they are.

Also the value of row.

I don’t see how you can get a ValueError. Are you sure it’s not

Can you please start by copying and pasting the actual error message you
get? The entire traceback, not just the last line. It should start with
the word “Traceback”.

Thanks for your reply. Here is the error message and a part of the code that’s relevant.

Traceback (most recent call last):
File “/home/exhile/PycharmProjects/BinanceBot/”, line 371, in
File “/home/exhile/PycharmProjects/BinanceBot/”, line 282, in UpDownRatio
mir = mir[cnow] # cnow geeft huidige coin aan
KeyError: 1

part of code…

 cnow = 0  # counter for loop value
 mon = collectlist[0]  # vergelijk waarde is 12 * 5 seconden geleden (1min)
 #mor = collectlist.copy()  # haal op een na recentste waarde op vd koers
 mir = collectlist[0]
 global posNeg,avPosneg, highpos, upCounter, XRP, XRPprice, sellList,inPos, relativ
 avPosneg, posNeg = 0.0, 0.0  # posNeg = average % of cryptos going up or down
 for value in currentPrices:
        print('check min ' + str(len(mir)))
        mir = mir[cnow]  # cnow geeft huidige coin aan
        print('check mon ' + str(len(mon)))
        mon = mon[cnow]
        cnow += 1

Thank you for posting the actual error. It’s not ValueError, its
KeyError, and that means that mir is not a list as we were told but a
dict. That makes things quite different from what we were told.

Do you understand the differences between a list and dict? If you have a
dict but try to use it as if it were a list, you will have many
problems. It’s like you have a screwdriver but try to use it as a

Why do you think that the mir contains keys 0, 1, 2, …?

How is mir created and what’s in it?

You are asking us to debug code that we can’t see and don’t know the
data being used. That is difficult, which is why we have to ask so many

It might help if you read this:

Thanks for replying, the strange thing is that mon works just fine. Why does ‘mon’ work but ‘mir’ not ?

Why do you assume that mon “works”?

As error is raised on attempt to access mir which is before you try to access man then there is no evidence that it will not raise an error.

On the contrary, with high probability it will also raise an error. You can verify what happens by just moving mon = mon[cnow] before mir = mir[cnow]

Also it could be beneficial for you to use built-in breakpoint() to inspect state of your code more closely.

Guys I fixed it by changing mon = mon[cnow] to mir = mon[cnow]. When I want to acces values in collectlist[10] I could do:
mar = collectList[10]
mer = mar[cnow]

Cheers everyone

Gerald asks:

“Why does ‘mon’ work but ‘mir’ not ?”

Why does it work when I hit nails with a hammer, but when I hit a cup
of coffee with a hammer it just makes a huge mess?

Why does it work when I roast potatoes but not when I roast salad?

Your two variables contain different things. Either different values of
the same type, or maybe different types of things, but either way they
are different. Because they are different, what you can do to them to
make them “work” is different. Programming is all about matching the
right tool to the right data to get the result you want.

>>> thing = [20, 30, 40]
>>> thing[0]  # works
>>> thing['key']  # doesn't work
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers or slices, not str

Without knowing what is in mon and mir, I cannot be more specific.

Thanks for clearing that up. It will keep this in notice in the future.