Re: One-liner to merge lists?

2022-02-27 Thread Peter Otten
On 27/02/2022 17:28, Chris Angelico wrote: On Mon, 28 Feb 2022 at 03:24, MRAB wrote: On 2022-02-27 08:51, Barry Scott wrote: On 22 Feb 2022, at 09:30, Chris Angelico wrote: On Tue, 22 Feb 2022 at 20:24, Frank Millman mailto:fr...@chagford.com>> wrote: Hi all I think this should be a s

Re: One-liner to merge lists?

2022-02-27 Thread Chris Angelico
On Mon, 28 Feb 2022 at 03:24, MRAB wrote: > > On 2022-02-27 08:51, Barry Scott wrote: > > > > > >> On 22 Feb 2022, at 09:30, Chris Angelico wrote: > >> > >> On Tue, 22 Feb 2022 at 20:24, Frank Millman >> > wrote: > >>> > >>> Hi all > >>> > >>> I think this should be a

Re: One-liner to merge lists?

2022-02-27 Thread MRAB
On 2022-02-27 08:51, Barry Scott wrote: On 22 Feb 2022, at 09:30, Chris Angelico wrote: On Tue, 22 Feb 2022 at 20:24, Frank Millman mailto:fr...@chagford.com>> wrote: Hi all I think this should be a simple one-liner, but I cannot figure it out. I have a dictionary with a number of keys,

Re: One-liner to merge lists?

2022-02-27 Thread Barry Scott
> On 22 Feb 2022, at 09:30, Chris Angelico wrote: > > On Tue, 22 Feb 2022 at 20:24, Frank Millman > wrote: >> >> Hi all >> >> I think this should be a simple one-liner, but I cannot figure it out. >> >> I have a dictionary with a number of keys, where each value

Re: One-liner to merge lists?

2022-02-26 Thread Chris Angelico
On Sun, 27 Feb 2022 at 16:35, Dan Stromberg wrote: > > > On Fri, Feb 25, 2022 at 3:15 PM Chris Angelico wrote: >> >> But ultimately, that's still the same as sum(), and it's no more >> readable than chain(), so I'd still be inclined to go with chain and >> then wrap it in a function if you need t

Re: One-liner to merge lists?

2022-02-26 Thread Dan Stromberg
On Fri, Feb 25, 2022 at 3:15 PM Chris Angelico wrote: > But ultimately, that's still the same as sum(), and it's no more > readable than chain(), so I'd still be inclined to go with chain and > then wrap it in a function if you need the clarity. > "Need" the clarity? Please tell me you don't th

Re: One-liner to merge lists?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 10:05, Albert-Jan Roskam wrote: >Was also thinking about reduce, though this one uses a dunder method: >from functools import reduce >d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} >print(reduce(list.__add__, list(d.values( If you don't want to use th

Re: One-liner to merge lists?

2022-02-25 Thread Albert-Jan Roskam
If you don't like the idea of 'adding' strings you can 'concat'enate: >>> items = [[1,2,3], [4,5], [6]] >>> functools.reduce(operator.concat, items) [1, 2, 3, 4, 5, 6] >>> functools.reduce(operator.iconcat, items, []) [1, 2, 3, 4, 5, 6] The latter is the functio

Re: One-liner to merge lists?

2022-02-23 Thread Peter Otten
On 22/02/2022 10:44, Frank Millman wrote: On 2022-02-22 11:30 AM, Chris Angelico wrote: On Tue, 22 Feb 2022 at 20:24, Frank Millman wrote: Hi all I think this should be a simple one-liner, but I cannot figure it out. I have a dictionary with a number of keys, where each value is a single li

Re: One-liner to merge lists?

2022-02-22 Thread Frank Millman
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 exercis

Re: One-liner to merge lists?

2022-02-22 Thread Avi Gross via Python-list
27;, 'ggg', 666, 'e', 'u', 'a', 'o', 'i'] The quest for a one-liner sometimes forgets that a typical function call is also a one-liner, with the work hidden elsewhere, often in a module written in python or mainly in C and so on. I suspect m

Re: One-liner to merge lists?

2022-02-22 Thread Chris Angelico
On Wed, 23 Feb 2022 at 15:04, Dan Stromberg wrote: > > On Tue, Feb 22, 2022 at 7:46 AM 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'] > > >>> >

Re: One-liner to merge lists?

2022-02-22 Thread Dan Stromberg
On Tue, Feb 22, 2022 at 7:46 AM 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'] > >>> > I like that way best. But I'd still: 1) use a little more descriptive

Re: One-liner to merge lists?

2022-02-22 Thread Avi Gross via Python-list
am NOT saying this is a good way but that it is sort of a one-liner. There are good reasons I do not see people doing things this way! -Original Message- From: Frank Millman To: python-list@python.org Sent: Tue, Feb 22, 2022 4:19 am Subject: One-liner to merge lists? Hi all I think t

RE: One-liner to merge lists?

2022-02-22 Thread David Raymond
> 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'] >>> -- https://mail.python.org/mailman/listinfo/python-list

Re: One-liner to merge lists?

2022-02-22 Thread Chris Angelico
On Tue, 22 Feb 2022 at 20:46, Frank Millman wrote: > > On 2022-02-22 11:30 AM, Chris Angelico wrote: > > On Tue, 22 Feb 2022 at 20:24, Frank Millman wrote: > >> > >> Hi all > >> > >> I think this should be a simple one-liner, but I cannot figure it out. > >> > >> I have a dictionary with a number

Re: One-liner to merge lists?

2022-02-22 Thread Frank Millman
On 2022-02-22 11:30 AM, Chris Angelico wrote: On Tue, 22 Feb 2022 at 20:24, Frank Millman wrote: Hi all I think this should be a simple one-liner, but I cannot figure it out. I have a dictionary with a number of keys, where each value is a single list - >>> d = {1: ['aaa', 'bbb', 'ccc'],

Re: One-liner to merge lists?

2022-02-22 Thread Chris Angelico
On Tue, 22 Feb 2022 at 20:24, Frank Millman wrote: > > Hi all > > I think this should be a simple one-liner, but I cannot figure it out. > > I have a dictionary with a number of keys, where each value is a single > list - > > >>> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} > > I want to com

One-liner to merge lists?

2022-02-22 Thread Frank Millman
Hi all I think this should be a simple one-liner, but I cannot figure it out. I have a dictionary with a number of keys, where each value is a single list - >>> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} I want to combine all values into a single list - >>> ans = ['aaa', 'bbb', 'ccc'