On 02.03.2023 18:27, Rob Cliffe via Python-ideas wrote:
Tl;dr: Join strings together with exactly one space between non-blank
text where they join.
I propose a meaning for
s1 & s2
where s1 and s2 are strings.
Namely, that it should be equivalent to
s1.rstrip() + (' ' if (s1.strip() and s2.strip()) else '') +
s2.lstrip()
Informally, this will join the two strings together with exactly one space
between the last non-blank text in s1 and the first non-blank text in s2.
Example: " bar " & " foo " == " bar
foo "
I don't find these semantics particularly intuitive. Python already has
the + operator for concatenating strings and this doesn't apply any
stripping.
If you're emphasizing on joining words with single space delimiters,
then the usual:
def join_words(list_of_words)
return ' '.join([x.strip() for x in list_of_words])
works much better. You can also apply this recursively, if needed, or
add support for list_of_phrases (first splitting these into a
list_of_words).
The advantage of join_words() is that it's easy to understand and
applies stripping in a concise way. I use such helpers all the time.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Experts (#1, Mar 06 2023)
>>> Python Projects, Coaching and Support ... https://www.egenix.com/
>>> Python Product Development ... https://consulting.egenix.com/
________________________________________________________________________
::: We implement business ideas - efficiently in both time and costs :::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
https://www.egenix.com/company/contact/
https://www.malemburg.com/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/IQWVHHNXNFFVWCSSLHWVFF5LCAPVSR2J/
Code of Conduct: http://python.org/psf/codeofconduct/