Logo

Programming-Idioms

History of Idiom 53 > diff from v42 to v43

Edit summary for version 43 by programming-idioms.org:
[Python] 2 ways => 2 impls => new impl 1933

Version 42

2016-12-22, 09:26:47

Version 43

2016-12-22, 09:27:39

Idiom #53 Join a list of strings

Concatenate elements of string list x joined by the separator ", " to create a single string y.

Illustration

Idiom #53 Join a list of strings

Concatenate elements of string list x joined by the separator ", " to create a single string y.

Illustration
Code
y = ", ".join(x)
# OR if x not only contains strings
y = ', '.join(str(v) for v in x)
Code
y = ', '.join(x)
Comments bubble
This works only if x contains only strings.
Comments bubble
This works if x contains only strings.
Doc URL
https://docs.python.org/3/library/stdtypes.html#str.join
Doc URL
https://docs.python.org/3/library/stdtypes.html#str.join