0

How do I concatenate two lists in Python with the same size?

Example:

    listname = ['jhon', 'maria', 'peter']
    listage = [18, 25, 14]

Expected outcome:

    finallist = [['jhon',18], ['maria',25], ['peter', 14]]

1 Answers1

2

You can try:

>>> 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)]
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61