Skip to content
Advertisement

How to combine the values in two lists Python

I have two lists: Names = [John, Marc, Alex] Surnames = [Stuart, Smith, Jones]

I would like to get the next list: [John-Stuart, Marc-Smith, Alex-Jones] How can I get it?

Advertisement

Answer

Use zip()

names = [John, Marc, Alex]
surnames = [Stuart, Smith, Jones]

fullnames = [f"{name}-{surname}" for name, surname in zip(names, surnames)]

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement