Message352532
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 ;-) |
|
Date |
User |
Action |
Args |
2019-09-16 09:53:43 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, christian.heimes, eric.araujo, josh.r, Javier Dehesa, iamsav |
2019-09-16 09:53:43 | serhiy.storchaka | set | messageid: <1568627623.68.0.0713012424787.issue33214@roundup.psfhosted.org> |
2019-09-16 09:53:43 | serhiy.storchaka | link | issue33214 messages |
2019-09-16 09:53:43 | serhiy.storchaka | create | |
|