[Python-ideas] Add list.join() please
Steven D'Aprano
steve at pearwood.info
Wed Jan 30 03:20:46 EST 2019
On Wed, Jan 30, 2019 at 12:09:55AM +0000, Alex Shafer wrote:
> 2) strings are special and worthy of a "special case" because strings
> tend to be human readable and are used in all kinds of user interface.
So are ints, floats, bools, lists, tuples, sets, dicts, etc.
We already have a "stringify" function that applies to one object at a
time. It's spelled str(), or if you prefer a slightly different format,
repr().
To apply the stringify function of your choice to more than one object,
you can use a for-loop, or a list comprehension, or a set comprehension,
or map(). This is called composition of re-usable components, and it is
a Good Thing.
If you don't like the two built-in stringify functions, you can write
your own, and they still work with for-loops, comprehensions and map().
Best of all, we're not even limited to strings. Change your mind and
want floats instead of strings? Because these are re-usable, composable
components, you don't have to wait for Python 4.3 to get a list
floatify() method, you can just unplug the str() component and replace
it with the float() component.
--
Steve
More information about the Python-ideas
mailing list