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(ob.data.vertices)):
    c = i
    cippo = edge_conx[c]
    print(cippo)

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]
    print(cippo)

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])

1
4
5
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:

Regards,

get it. thanks