Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Concatenate elements in list by order in Python

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading