[issue33214] join method for list and tuple
Serhiy Storchaka
report at bugs.python.org
Mon Sep 16 05:53:43 EDT 2019
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
How common is the case of variable number of things to concatenate/union/merge?
>From my experience, in most ceases this looks like:
result = []
for ...:
# many complex statements
# may include continue and break
result.extend(items) # may be intermixed with result.append(item)
So concatenating purely lists from some sequence is very special case. And there are several ways to perform it.
result = []
for items in seq:
result.extend(items)
# nothing wrong with this simple code, really
result = [x for items in seq for x in items]
# may be less effective for really long sublists,
# but looks simple
result = list(itertools.chain.from_iterable(items))
# if you are itertools addictive ;-)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33214>
_______________________________________
More information about the Python-bugs-list
mailing list