Actually, your code works as it is now. The KeyError '0' , i.e. - the key is str shown suggest you tried with
1. don't use
2. actualsearch is int, the keys in the dict are also int. there is no need of any conversion
3. it's good to use dict.get() method to avoid KeyError if key is missing
if dict[str(actualsearch)]==41:
actualsearch=0 dict={0:41, 1:41, 2:41} if dict[int(actualsearch)]==41: #I try int and str, but both dosen't work actualsearch=actualsearch+1 print(actualsearch)output
Output:1
several other things1. don't use
dict
as variable name, it's a built-in function and you override it2. actualsearch is int, the keys in the dict are also int. there is no need of any conversion
3. it's good to use dict.get() method to avoid KeyError if key is missing
actual_search = 0 my_dict = {0:41, 1:41, 2:41} if my_dict.get(actual_search) == 41: # do something actual_search += 1
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs