[Python-ideas] [...].join(sep)
Simon Sapin
simon.sapin at kozea.fr
Sat May 12 10:34:26 CEST 2012
Le 12/05/2012 10:21, anatoly techtonik a écrit :
> I am certain this was proposed many times, but still - why it is rejected?
>
> "real man don't use spaces".split().join('+').upper()
> instead of
> '+'.join("real man don't use spaces".split()).upper()
>
>
> The class purity (not being dependent from objects of other class) is
> not an argument here:
> string.join() produces list, why list.join() couldn't produce strings?
>
> The impedance mismatch can be, but it is a pain already and
> string.join() doesn't help:
> that means you still get exception when trying to join lists with
> no strings inside
>
>
> Can practicality still beat purity in this case?
Hi,
I’m not sure what you mean by "class purity", but the argument against
this is practical: list.join would work but we want to join iterables,
not just lists.
bytes.join and str.join accept any iterable (including user-defined
ones), while not every iterable would have a join method.
Having the burden of defining join on user-defined string-like types
(not very common) is better than on user-defined iterables (more
common). Also, a "string-like" already needs many methods while __iter__
is enough to make an iterable.
--
Simon Sapin
More information about the Python-ideas
mailing list