Home > Net >  Concatenate elements in list by order in Python
Concatenate elements in list by order in Python

Time:02-18

I'm doing web scraping for prices, and in this particular site, they have the main prices in one class, and the cents in another class.

enter image description here

Basically I'm attributing each class to a list, so I'll end up with something looking like this:

prices = ["69", "99", "109"]
decimals = [",90", ",99", ",89"]

What I need is the resulting list:

full_price = ["69,90", "99,99", "109,89"]

I tried using two loops and append, but ended up having multiple undesired combinations. enter image description here

How to I achieve the full_price list desired?

CodePudding user response:

You can achieve it rather easily by using zip:

prices = ["69", "99", "109"]
decimals = [",90", ",99", ",89"]
full_price = [''.join(x) for x in zip(prices, decimals)]
  • Related