Spot the swapped state/action indices when writing to a Q-table.
Codepython
n_states = 5
n_actions = 4
# Q-table: one row per state, one column per action
Q = [[0.0 for _ in range(n_actions)] for _ in range(n_states)]
def update(state, action, value):
Q[action][state] = value
# state can be 0..4, action can be 0..3
update(state=4, action=1, value=2.5)