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