【问题标题】:How to concatenate two list? [duplicate]如何连接两个列表? [复制]
【发布时间】: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


    【解决方案1】:

    你可以试试:

    >>> 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)]
    

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 1970-01-01
      • 2018-11-06
      • 2012-05-23
      • 2021-07-11
      • 2013-12-14
      • 2016-01-12
      • 1970-01-01
      • 2019-08-17
      相关资源
      最近更新 更多