我有以下数据结构:
a = [('customerA', '1.0.0'), ('customerB', '1.0.0'), ('customerC', '1.0.1')]
b = (('customerB', '1.1.0'), ('customerC', '1.0.1'))
我希望结果是这样的:
^{pr2}$甚至完全跳过不存在的客户:
[('customerB', '1.0.0', '1.1.0'), ('customerC', '1.0.1', '1.0.1')]
在这种情况下,zip
函数没有帮助,因为b
来自客户名称的MySQLCursor.fetchall()
withWHERE
子句,因此如果客户不存在,它将与a
不匹配:
>>> [a + (b[1],) for a, b in zip(a, b)]
[('customerA', '1.0.0', '1.1.0'), ('customerB', '1.0.0', '1.0.1')]
>>> import itertools
>>> for a, b in itertools.zip_longest(a, b):
... print(a, b)
...
('customerA', '1.0.0') ('customerB', '1.1.0')
('customerB', '1.0.0') ('customerC', '1.0.1')
('customerC', '1.0.1') None
使用
collections
。在演示:
输出:
^{pr2}$你试过直接做吗?在
现在,
^{pr2}$result
就是相关问题 更多 >
编程相关推荐