1
  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?

3
  • What are you actually trying to achieve? Commented Nov 19, 2013 at 18:00
  • Make your Question more Clear Commented Nov 19, 2013 at 18:02
  • @wcdolphin ['a', 'b'] to print 'a' or 'b' Commented Nov 19, 2013 at 19:39

1 Answer 1

5

You can use repr:

>>> a = ['a', 'b']
>>> print " or ".join(repr(i) for i in a)
'a' or 'b'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.