我有一份地址列表
addr1=['0x00800d00', 'numb=4', '0x00800d10', '0x00800d20', 'numb=4', '0x00800d30', '0x00800d40', '0x00800e00', '0x00800e04', '0x00800e10', '0x00800e14', '0x00800e18', '0x00800e1c', '0x00800e20', '0x00800e24', '0x00800e28', '0x00800e2c', 'numb=32', '0x00800e30']
我希望根据'numb=<x>'
中的值扩展列表。
即如果addr1[1]
是'numb=4'
,那么从addr[2]
的值开始,我想从addr[2]
开始填充列表中的四个地址作为 - &gt; '0x00800d10', '0x00800d14', '0x00800d18', '0x00800d1c'
并使用'numb='
所以addr2应该是这样的:
addr2=['0x00800d00', '0x00800d10', '0x00800d14', '0x00800d18', '0x00800d1c', '0x00800d20', '0x00800d30', '0x00800d34','0x00800d38', '0x00800d3c', '0x00800d40',...... and so on]
答案 0 :(得分:1)
一种可能性:
addr2 = []
numb = 1
for addr in addr1:
if addr.startswith('numb='):
numb = int(addr[5:])
continue
addr_num = int(addr, 0)
for i in range(numb):
addr2.append("{0:#0{1}x}".format(addr_num, 10))
addr_num += 4
numb = 1