One-liner to merge lists?
Frank Millman
frank at chagford.com
Wed Feb 23 01:15:26 EST 2022
On 2022-02-22 5:45 PM, David Raymond 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']
>>>>
>
Now that's what I was looking for.
I am not saying that I will use it, but as an academic exercise I felt
sure that there had to be a one-liner in pure python.
I had forgotten about nested comprehensions. Thanks for the reminder.
Frank
More information about the Python-list
mailing list