I have the following list of tuples
a = [(5, 2), (2, 4)]
And I need to output the following text
(5,2) (2,4)
I have tried
[",".join(str(i) for i in j) for j in a]
And it provides the following list
['5,3', '2,4']
But haven't found an efficient way of getting the desired output, and it must work for a list of tuples of different sizes.
You can use the str.join
method with a generator expression like the following:
' '.join('(%s)' % ','.join(map(str, t)) for t in a)
This returns a string with the following content:
(5,2) (2,4)
If all you need to do is get string output then:
str(a).strip("[]")
out:
'(5,2) (2,4)'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With