Logo

Programming-Idioms

History of Idiom 53 > diff from v51 to v52

Edit summary for version 52 by fen:
[Python] Idiomatic usage of the map builtin to replace a list comprehension that just calls a function

Version 51

2019-04-14, 17:37:12

Version 52

2019-05-12, 19:56:56

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(str(v) for v in x)
Code
y = ', '.join(map(str, x))
Comments bubble
This works even if some elements in x are not strings.
Comments bubble
This works even if some elements in x are not 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