numpy - Python: Printing elements in the defaultdict based on the order in the OrderedDict -


import string collections import namedtuple collections import defaultdict collections import ordereddict  matrix_col = {'11234':0, '21234':2, '31223':0, '46541':0, '83432':1, '56443':2, '63324':0, '94334':0, '72443':1} matrix_col = ordereddict(sorted(matrix_col.items(), key=lambda t: t[0]))  trans = defaultdict(dict) trans['11234']['46541'] = 2 trans['11234']['21234'] = 1 trans['11234']['31223'] = 2 trans['11234']['83432'] = 1 trans['21234']['31223'] = 2 trans['21234']['46541'] = 1 trans['21234']['72443'] = 1 trans['21234']['83432'] = 1 trans['56443']['72443'] = 1 trans['56443']['83432'] = 1  u1, v1 in matrix_col.items():     u2, v2 in matrix_col.items():         w1 in trans.keys():             w2, c in trans[u1].items():                 if u1 == str(w1) , u2 == str(w2):                     print u1, u2, c   

as above, trying print elements of trans (defaultdict) based on sorted order of elements in matrix_col (ordereddict) , unable that. below expected output, can't generate:

11234 11234 0 11234 21234 1 11234 31223 2 11234 46541 2 11234 56443 0 11234 63324 0 11234 72443 0 11234 83432 1 11234 94334 0 21234 11234 0 21234 21234 0 21234 31223 2 21234 46541 1 21234 56443 0 21234 63324 0 21234 72443 1 21234 83432 1 21234 94334 0 31223 11234 0 31223 21234 0 31223 31223 0 31223 46541 0 31223 56443 0 31223 63324 0 31223 72443 0 31223 83432 0 31223 94334 0 ... 

any appreciated.

i able solve it. here is:

for u1, v1 in matrix_col.items():     u2, v2 in matrix_col.items():         bastim = true         w1 in trans.keys():             w2, c in trans[u1].items():                 if u1 == str(w1) , u2 == str(w2):                     print u1, u2, c                       bastim = false         if bastim:             print u1, u2, 0 

thank all.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -