How to group and assign values of dictionary into single key in python -


i have memory of intel hex file

1879048192: 4, 1879048193: 3, 1879048194: 2, 1879048195: 1, 1879048196: 4, 1879048197: 3, 1879048198: 2, 1879048199: 1, 1879048200: 4, 1879048201: 3, 1879048202: 2, 1879048203: 1, 1879048204: 4, 1879048205: 3, 1879048206: 2, 1879048207: 1, 

i want have

1879048192: 1234(with swapping), 1879048196 :1234 1879048200 :1234 1879048204 :1234 1879048208 :1234 

i using

for x in range (0,count):     in range(0,4):         realdata = mapfile.values()[x:x+4]         realdata[x+3],realdata[x+2],realdata[x+1],realdata[x+0] =                realdata[x+0],realdata[x+1],realdata[x+2],realdata[x+3]          s = ''.join(map(str, realdata))          realadr = mapfile.keys()[x] + offset          offset = offset + 4          _buf = {realadr : int(s)} 

but not able success, new python. please suggest me better implementation.

_buf = {realaddr : int(s)} 

causes _buf dictionary single entry, last values of realaddr: int(s). that's not want. move outside , add logic merging values:

_buf = {} x in range (0,count):     in range(0,4):         realdata = mapfile.values()[x:x+4]         realdata[x+3],realdata[x+2],realdata[x+1],realdata[x+0] =                realdata[x+0],realdata[x+1],realdata[x+2],realdata[x+3]          s = ''.join(map(str, realdata))          realadr = mapfile.keys()[x] + offset          offset = offset + 4          if realadr in _buf:            # merge values somehow            s = _buf[realadr] + s          _buf[realadr] = int(s)  print _buf 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -