pavelkolodin
pavelkolodin

Reputation: 2967

Python: simplest way to join strings inserting a string between them?

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 )

Upvotes: 1

Views: 163

Answers (2)

Inbar Rose
Inbar Rose

Reputation: 43447

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.

Upvotes: 2

jamylak
jamylak

Reputation: 133534

>>> strs = ['x=1', 'b=4', 'x=4']
>>> print ' AND '.join(strs)
x=1 AND b=4 AND x=4

Upvotes: 8

Related Questions