【发布时间】:2011-09-19 20:53:55
【问题描述】:
我有两个列表 - 即
[['1', 'expired', 'test', '0'], ['31', 'active', 'test', '1']]
还有
[['1', 'Andrew', 'Alexander'], ['31', 'John', 'Smith']]
我们称他们为list1 和list2
我想合并 list1 和 list2,但仅限于(注意,这是伪代码,试图弄清楚如何在 Python 中编程)
x[0] in list1 == x[0] in list2
我不知道怎么写出来。
我的意思是合并(伪代码)
list[x] = list1[x] + list2[x] while x[0] in list1 == x[0] in list2
所需的输出:
[['1', 'expired', 'test', '0', '1', 'Andrew', 'Alexander'], ['31', 'active', 'test', '1', '31', 'John', 'Smith']]
唯一的关键点是并非所有的 x[0] 都会完美匹配。
【问题讨论】:
-
这里的“合并”到底是什么意思?期望的输出是什么?
-
请准确给出您希望示例输出的内容——我还不是很清楚。
-
仍在尝试找出适合我的正确答案。我的很多未选择的答案都是这样的。过去我也一直试图给问题打勾。我正在努力成为社区的好成员!