Logo

Programming-Idioms

History of Idiom 53 > diff from v20 to v21

Edit summary for version 21 by :

Version 20

2015-10-31, 16:43:13

Version 21

2015-11-30, 12:37:29

Idiom #53 Join a list of strings

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

Idiom #53 Join a list of strings

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

Code
y = ", ".join(x)
# OR if x not only contains strings
y = ', '.join(str(v) for v in x)
Code
y = ", ".join(x)
# OR if x not only contains strings
y = ', '.join(str(v) for v in x)
Comments bubble
This works only if x contains only strings.
Comments bubble
This works only 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