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

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

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

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

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

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

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

Re: One-liner to merge lists?

2022-02-22 Thread Avi Gross via Python-list
re available with a little search that handle more including just about any iterable that terminates. -Original Message- From: Dan Stromberg To: David Raymond Cc: python-list@python.org Sent: Tue, Feb 22, 2022 11:02 pm Subject: Re: One-liner to merge lists? On Tue, Feb 22, 2022 at 7:46 AM

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

Re: One-liner to merge lists?

2022-02-22 Thread Avi Gross via Python-list
Frank, Given this kind of data: d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} You seem focused on a one-liner, however ridiculous or inefficient. Does this count as a somewhat weird one liner? comb = []; _ = [comb.append(v) for v in d.values()] If you run the code and ignore the

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

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