Here's a very readable way to concatenate strings using "+="
on lists:

>>> l = []
>>> l += ['abc']
>>> l += ['abc']
>>> l += ['abc']
>>> l += ['abc']
>>> s = ''.join(l)
>>> s
'abcabcabcabc'

Probably not exactly what Paul had in mind, but it's beginners
friendly.

The string version, with O(N²) timing, reads like this:

>>> s = ''
>>> s += 'abc'
>>> s += 'abc'
>>> s += 'abc'
>>> s += 'abc'
>>> s
'abcabcabcabc'

BTW: I think the above is a great example to teach beginners that
choosing the right algorithm is rather important when it comes to
dealing with large data sets. It's also a good example of why
O(N²) isn't necessarily bad for small data sets.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Mar 22 2020)
>>> 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/GEPUC67A4B2ZWO5HWD5CEEVERHYP2JS2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to