hash - Sorting two hashes into one in Python -


i have 2 hash fp['netc'] containing cells connected specific net example:

'net8': ['cell24', 'cell42'], 'net19': ['cell11', 'cell16', 'cell23', 'cell25', 'cell32', 'cell38'] 

and fp['celld_nm'] containing x1,x0 coordinate each cell example:

{'cell4': {'y1': 2.164, 'y0': 1.492, 'x0': 2.296, 'x1': 2.576}, 'cell9': {'y1': 1.895, 'y0': 1.223, 'x0': 9.419, 'x1': 9.99} 

i need create new hash (or list) give x0 , x1 each cell in spesific net. instance:

net8: cell24 {xo,x1} cell42 {xo,x1} net 18: cell11 {xo,x1} ...

here code

l1={} l0={} net in fp['netc']:      cell in fp['netc'][net]:             x1=fp['celld_nm'][cell]['x1']             x0=fp['celld_nm'][cell]['x0']              l1[net]=x1             l0[net]=x0 print l1 print l0 

all got last value each net.

do have ideas?

the issue you're having you're generating x0 , x1 values each cell, assigning results per net. since each net has multiple cells, overwrites last values each of them.

it looks instead want nested dictionaries, you'd index x0[net][cell]. here's how can that:

l0 = {} l1 = {} net, cells in fp['netc'].items(): # use .iteritems() if you're using python 2     l0[net] = {}     l1[net] = {}     cell in cells:         l0[net][cell] = fp['celld_nm'][cell]['x0']         l1[net][cell] = fp['celld_nm'][cell]['x1'] 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -