Reputation: 12452
1 def add(i):
2 return '\''+i+'\''
3 a = ['a', 'b']
4 print " or ".join([add(i) for i in a])
OUTPUT: 'a' or 'b'
I am not sure if the above is the best way (esp the add function).
Is there a better way to achieve what I am trying to do?
Upvotes: 1
Views: 73
Reputation: 250871
You can use repr
:
>>> a = ['a', 'b']
>>> print " or ".join(repr(i) for i in a)
'a' or 'b'
Upvotes: 5