List accessing in Python -


i have 2 list this

nodelist1=[[['b', 10], ['in', 1000]], [['c', 15], ['out', 1001]], [['f', 30], ['in', 1100]]] nodelist2= [[['g', 20], ['in', 1000, 'out', 1111]], [['d', 25], ['inward', 1]]] 

what trying comparing these 2 lists

if len(nodelist1[i][1])==len(nodelist2[j][1])  

if condition true want remove nodelist1[i][0] ['b', 10] , nodelist1 , nodelist2[j][1] ['d', 25] nodelist2.

then should have

nodelist1 [[['c', 15], ['out', 1001]], [['f', 30], ['in', 1100]]] nodelist2 [[['g', 20], ['in', 1000, 'out', 1111]]] 

my code this:

   if len(nodelist1)>len(nodelist2):       in range(len(nodelist1)):          j in range(len(nodelist2)):             if len(nodelist1[i][1])==len(nodelist2[j][1]):                 if nodelist1[i][1]==nodelist2[j][1]:                     nodelist1.remove(nodelist1[i])                     nodelist2.remove(nodelist2[j])                   else:                     nodelist1.remove(nodelist1[i])                     nodelist2.remove(nodelist2[j])   

it gives me error:

if len(nodelist1[i][1])==len(nodelist2[j][1]):     indexerror: list index out of range 

you removing elements list while looping through it. when moving end of list, there not enough elements. , index accessing raise indexerror.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -