我在生成列表方面很弱。请帮助我如何获得这种结构:
cash = [[01110101010, {'01110101010100010000000110010100': 1477317843.506, '01110101010100010000000110010101': 1477317843.906}], 01110101011, {'01110101011100010000000110010100': 1477317843.506, '01110101011100010000000110010101': 1477317843.906}]]
例如: 现金bloch: 块[0] [0]为01110101010,它始终等于相应字典中每个键的前11个数字。如果它们的前11个数字等于块[i] [0]
,则键添加来自这个狭窄:
cash = [[01110101010, {'01110101010100010000000110010100': 1477317843.506}], [01110101010, {'01110101010100010000000110010101': 1477317843.906}], [01110101011, {'01110101011100010000000110010100': 1477317843.506}], [01110101011 {'01110101011100010000000110010101': 1477317843.906}]]
例如: 现金bloch: block [0] [0]为01110101010,它总是等于相应字典中所有键的前11个。
答案 0 :(得分:0)
假设您正在使用Python(通过查看您的数据结构),以下解决方案应该适合您
注意:我已经编辑了你的输入,使第一个元素成为字符串,因为以0开头的数字被解释为八进制,我认为这不是你想要的
dyld`dyld_fatal_error: -> 0x1200a1088 <+0>: brk #0x3
以下操作应该没问题
cash = [
['01110101010',{'01110101010100010000000110010100': 1477317843.506}],
['01110101010', {'01110101010100010000000110010101': 1477317843.906}],
['01110101011', {'01110101011100010000000110010100': 1477317843.506}],
['01110101011', {'01110101011100010000000110010101': 1477317843.906}]
]
op = dict()
for entry in cash:
key = entry[0]
value = entry[1]
op.setdefault(key,{})
op[key].update(value)
但如果您坚持列表,那么
{
'01110101011': {'01110101011100010000000110010101': 1477317843.906, '01110101011100010000000110010100': 1477317843.506},
'01110101010': {'01110101010100010000000110010100': 1477317843.506, '01110101010100010000000110010101': 1477317843.906}
}
会给你以下格式**
op_list = []
for key in op.keys():
op_list.append([key, op[key]])