python - iterate through a dictionary that has a list within lists -


i'm trying figure out way match value in nested list in dictionary. let's have structure;

dict2 = {'key1': [ 2, ['value1', 3], ['value2', 4] ], 'key2' : [1, ['value1', 2], ['value2', 5] ], 'key3' : [7, ['value1', 6], ['value2', 2], ['value3', 3] ] } 

now let's key1, want iterate through first value of lists data match. if data "value2" , want in key1, want skip '2' , check first object in 2 lists are; value1, value2 match , that's it.

tried doing gave keyerror: 1;

if 'value1' in dict2[1][1:]:     print 'true' else:     print 'false' 

is possible do? there way match search? thanks.

the code in question using numeric index instead of string 'key1'. here's modified version should work:

if 'value1' in {array[0] array in dict2.get('key1', [])[1:]}:     print 'true' else:     print 'false' 

that looks @ of elements after first in array associated 'key1' in dictionary, if exists.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -