Strange error (for me!) in a for loop

Hi all,
Edge_conx is a dict() of list. I want to iterate through the dictionary and calling the list
The key values are integer (0, 1, 2, 3, ecc…)
this works

for i in range(len(
    c = i
    cippo = edge_conx[c]

but this not, the error says “int object is not subscriptable”.

for edge, edge_conx in enumerate(edge_conx):
    c = i
    cippo = edge_conx[c]

I don’y understand. Hints?
Thanks Paolo

I think, your enumerate is not ok … at least I think so

meaning you edge_conx is used twice??? veriy strange???
Test in the console:
>>> my = { 0:1,4:4,6:5}
>>> for a,b in enumerate(my):print(a,b)

0 0
1 4
2 6

#########means keys are shown

>>> for a,b in enumerate(my):print(my[b])

Maybe you want this?

Well in my code i has nothing to do… my fault. But if I try fro your code my = { 0:1,4:4,6:5}
>>> for a, b in enumerate(my):
… c = a
… cippo = my[c]
… print(cippo)
will print 1 and then “Key error: 1”

>>> for a, b in enumerate(my):
… c = a
… print(a)
Correctly print 0 1 2

It seems like isn’t possible to rewrite c in my[c] on the second loop
It’s not am important issue, only to grasp correctly when use range and when use enumerate…

Hmmm… “Key error: 1” comes from the fact that 1 is NOT amongst you keys in my

If my = { 0:1,4:4,6:5}, your keys are = [0, 4, 6] and your values are = [1, 4, 5] soooo… 1 is NOT a valid key which results in the error message you get :wink:


get it. thanks