Reputation: 633
I am trying to print this python list
as in the format value1
, value1
, value3
.
But what I get is something like this:
['value1', 'value2', 'value3']
So I want to get rid of '
and []
.
This is what I tried, but it now prints the result without only brackets:
tagList = []
count = 0
for i in range(20):
try:
if not response['TagList'][i]['Key']:
print("Tags not found")
else:
if str(response['TagList'][i]['Key']) == "t_AppID":
pass
tagList.append(str(response['TagList'][i]['Key']))
except:
pass
return str(tagList)[1:-1]
Upvotes: 1
Views: 104
Reputation: 9681
To return list elements as a string you can use something like:
def as_string(values):
return ', '.join(values)
print(as_string(['a', 'b', 'c'])
a, b, c
Upvotes: 0
Reputation: 181745
Use the join
function on str
:
>>> mylist = ['value1', 'value2', 'value3']
>>> print(mylist)
['value1', 'value2', 'value3']
>>> print(', '.join(mylist))
value1, value2, value3
Upvotes: 4