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

How do I use zip print on a list of strings in python without it returning with quotations surrounding them?

Current code:

reps = ['x 5', 'x 5', 'x 3', 'x 5', 'x 5', 'x 5+']
b = [90, 122, 135, 146, 168, 191]

print(str(list(zip(b,reps))).replace(',',''))

here is the current output:

[(90 'x 5') (112 'x 5') (135 'x 3') (146 'x 5') (168 'x 5') (191 'x 5+')]

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

here is my goal output:

[(90 x 5) (112 x 5) (135 x 3) (146 x 5) (168 x 5) (191 x 5+)]

How would I remove those single quotes?

I tried using replace but I’m not sure how to both replace the commas separating the weight and the reps, as well as the quotations around the rep range.

I also tried replacing the quotations in the list reps on a separate line of code but once it is printed within the zip they were added back.

>Solution :

It sounds like cosmetic output, but the following will work for your case:

print('[' + ' '.join(f"({x} {y})" for x, y in zip(b, reps)) + ']')

[(90 x 5) (122 x 5) (135 x 3) (146 x 5) (168 x 5) (191 x 5+)]
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