请问有人可以帮我从我的元组列表中删除多余的括号吗?
latest_Value = {"17:00:00": 100.00}
Dict1 = {"current value": 100, "stock_purchased": "false", "Historic value": [('16:00:00', 55.50), ("15:00:00", 45.50), ("14:00:00", 75.50),("13:00:00", 65.50), ("12:00:00", 55.50)]}
# converting the latest_value into a tuple
List_it = [(k, v) for k, v in latest_Value.items()]
# insert the tuple into the tuple list
Dict1['Historic value'].insert(0, List_it)
data2 = Dict1["Historic value"]
print(data2)
#output
[[('17:00:00', 100.0)], ('16:00:00', 55.5), ('15:00:00', 45.5), ('14:00:00', 75.5), ('13:00:00', 65.5), ('12:00:00', 55.5)]
当列表被修改时,它会添加一个嵌套列表而不仅仅是元组。你如何避免这种情况?
长风秋雁
相关分类