New submission from Dominik V. <[email protected]>:
The section mentions the usage of `str.join` and contains the following example:
chunks = []
for s in my_strings:
chunks.append(s)
result = ''.join(chunks)
Since `join` accepts any iterable the creation of the `chunks` list in a for
loop is superfluous. If people just copy & paste from this FAQ they'll even end
up with less performant code.
The example could be improved by providing an example list such as:
strings = ['spam', 'ham', 'eggs']
meal = ', '.join(strings)
Arguably this isn't a particularly long list of strings, so one more example
could be added using e.g. `range(100)`:
numbers = ','.join(str(x) for x in range(100))
This also emphasizes the fact that `join` takes any iterable rather than just
lists.
----------
assignee: docs@python
components: Documentation
messages: 366887
nosy: Dominik V., docs@python
priority: normal
severity: normal
status: open
title: Programming FAQ about "What is the most efficient way to concatenate
many strings together?" -- Improving the example
type: enhancement
versions: Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40344>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com