1
strs = ['x=1', 'b=4', 'x=4']

I want to get:

str = 'x=1 AND b=4 AND x=4'

What is a simplest way to do that in Python?

P.S. too stupid question
Found:

' AND '.join( strs )
1
  • 3
    You shouldn't call your variable str (not even for a quick example), there is a builtin str Commented Jun 20, 2013 at 10:03

2 Answers 2

8
>>> strs = ['x=1', 'b=4', 'x=4']
>>> print ' AND '.join(strs)
x=1 AND b=4 AND x=4
Sign up to request clarification or add additional context in comments.

Comments

2

You answered you own question, join is the way to do this.

' '.join(strs)

Will put a space between each item in strs. And the following:

' AND '.join(strs) 

Will put ' AND ' between each item.

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.