【发布时间】:2019-01-04 12:38:15
【问题描述】:
我有一个清单:
Online = [['Robot1', '23.9', 'None', '0'], ['Robot2', '25.9', 'None', '0']]
如果我收到不同的值,我想替换子列表:
NewSublist1 = ['Robot1', '30.9', 'Sending', '440']
NewSublist2 = ['Robot2', '50']
我想要:
Online = [['Robot1', '30.9', 'Sending', '440'], ['Robot2', '50']]
子列表元素的数量可能会改变。唯一相同的是机器人 ID。所以我想进行搜索,看看机器人 id 是否在在线列表中,并将子列表替换为新的。
【问题讨论】:
-
好的,这听起来很简单。你的代码是什么样的,你在哪里卡住了?
-
您要合并这些列表吗?
-
请贴出你目前写的代码,并通读Python数据结构教程:docs.python.org/3/tutorial/datastructures.html
标签: python list replace sublist