【发布时间】:2020-02-29 15:08:31
【问题描述】:
如何在 Python 中连接两个大小相同的列表?
例子:
listname = ['jhon', 'maria', 'peter']
listage = [18, 25, 14]
预期结果:
finallist = [['jhon',18], ['maria',25], ['peter', 14]]
【问题讨论】:
标签: python python-3.x
如何在 Python 中连接两个大小相同的列表?
例子:
listname = ['jhon', 'maria', 'peter']
listage = [18, 25, 14]
预期结果:
finallist = [['jhon',18], ['maria',25], ['peter', 14]]
【问题讨论】:
标签: python python-3.x
你可以试试:
>>> listname = ['jhon', 'maria', 'peter']
>>> listage = [18, 25, 14]
>>> zip(listname, listage)
<zip object at 0x000001E4734B6888>
>>> list(zip(listname, listage))
[('jhon', 18), ('maria', 25), ('peter', 14)]
【讨论】: