One-liner to merge lists?

Dan Stromberg drsalists at gmail.com
Tue Feb 22 23:02:57 EST 2022


On Tue, Feb 22, 2022 at 7:46 AM David Raymond <David.Raymond at tomtom.com>
wrote:

> > Is there a simpler way?
>
> >>> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']}
> >>> [a for b in d.values() for a in b]
> ['aaa', 'bbb', 'ccc', 'fff', 'ggg']
> >>>
>

I like that way best.

But I'd still:
1) use a little more descriptive identifiers
2) put it in a function with a descriptive name
3) give the function a decent docstring


More information about the Python-list mailing list