I don't understand how this is possible? Here I am using the value of i for the for loop, outside the for loop.
for i, kv in enumerate(bucket): 
    k, v = kv  
    if key == k:
        key_exists = True
        break 
#here is the issue...
if key_exists:
    bucket[i] = ((key, value))
    print(i)
else:
    bucket.append((key, value))
 
     
    