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

Advertisements

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

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

Leave a ReplyCancel reply