[Python-ideas] Re: Introduce constant variables in Python

2021-06-16 Thread tabeb qena
Great Idea, I have joined the mailing list to write the same idea. As I can't find the great difference between Final and Constant, So, I will use the name Final. I suggest one the following syntax: from collection import Final 》x = Final(100) 》print(x) 》100 》y = x*2 》Print(Y) 》200 》print (

[Python-ideas] Deprecate sum of lists

2021-06-16 Thread Oliver Margetts
Hi all, I came across the following performance issue with the sum function while summing lists: https://bugs.python.org/issue18305 It's been discussed previously in this list and other issues. The rationale in that ticket makes the case that performance won't be fixed because sum() should not be

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Rob Cliffe via Python-ideas
This seems sensible to me.  I remember Guido vetoing allowing random.choice() to accept a set, and for the same reason - it encourages inefficient code. Rob Cliffe On 16/06/2021 15:50, Oliver Margetts wrote: Hi all, I came across the following performance issue with the sum function while summ

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Steven D'Aprano
On Wed, Jun 16, 2021 at 02:50:06PM +, Oliver Margetts wrote: > Hi all, I came across the following performance issue with the sum function > while summing lists: https://bugs.python.org/issue18305 It's been discussed > previously in this list and other issues. Did you actually use sum to conc

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Christopher Barker
> > The performance error for strings should be considered an anomaly, not a > feature to be extended to anything that could be used, or misused, with > non-linear behaviour. I’m pretty sure that using sum with strings was a real issue in real code before it was disallowed. But the irony is tha

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Chris Angelico
On Thu, Jun 17, 2021 at 9:04 AM Christopher Barker wrote: > > > >> >> The performance error for strings should be considered an anomaly, not a >> feature to be extended to anything that could be used, or misused, with >> non-linear behaviour. > > > I’m pretty sure that using sum with strings was a

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Oliver Margetts
I came across this just processing JSON data - flattening a list of 'deals' into a list of individual 'trades'. Flattening nested lists is not uncommon. And yes sum seemed the natural way to do it at the time. Yes, you're right some people might find it convenient and use it in the REPL. It just s

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Oliver Margetts
> I'm not sure why it doesn't special-case it to "".join() One reason might be because you'd have to read the entire iterator to know if it really was only strings. So there are concerns with generators which complicate things a fair bit On Thu, 17 Jun 2021, 12:12 am Chris Angelico, wrote: > On

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Chris Angelico
On Thu, Jun 17, 2021 at 9:46 AM Oliver Margetts wrote: > > > I'm not sure why it doesn't special-case it to "".join() > One reason might be because you'd have to read the entire iterator to know if > it really was only strings. So there are concerns with generators which > complicate things a fa

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread MRAB
On 2021-06-17 00:57, Chris Angelico wrote: On Thu, Jun 17, 2021 at 9:46 AM Oliver Margetts wrote: > I'm not sure why it doesn't special-case it to "".join() One reason might be because you'd have to read the entire iterator to know if it really was only strings. So there are concerns with gen

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread David Mertz
On Wed, Jun 16, 2021 at 7:35 PM Oliver Margetts wrote: > I came across this just processing JSON data - flattening a list of > 'deals' into a list of individual 'trades'. Flattening nested lists is not > uncommon. And yes sum seemed the natural way to do it at the time. > I remember the discussi

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Christopher Barker
On Wed, Jun 16, 2021 at 8:04 PM David Mertz wrote: > Flattening nested lists is not uncommon. And yes sum seemed the natural >> way to do it at the time. >> > > I remember the discussion in 2013 about the quadratic performance of > summing strings. There were proposals for optimization of the s

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread David Mertz
On Thu, Jun 17, 2021, 1:14 AM Christopher Barker > I'm sympathetic to raising an exception on `sum(list_of_lists)` similar to >> `sum(list_of_strings)`. But what exactly is the recommended substitute? >> We have this: >> >> list(chain.from_iterable(list_of_lists)) >> > > If you read the BPO the O

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Chris Angelico
On Thu, Jun 17, 2021 at 3:27 PM David Mertz wrote: > > On Thu, Jun 17, 2021, 1:14 AM Christopher Barker >>> >>> I'm sympathetic to raising an exception on `sum(list_of_lists)` similar to >>> `sum(list_of_strings)`. But what exactly is the recommended substitute? >>> We have this: >>> >>> list(

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread David Mertz
On Thu, Jun 17, 2021, 1:38 AM Chris Angelico > >>> list(chain.from_iterable(list_of_lists)) > > > More-itertools has flatten(): > https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.flatten. > That seems better than a method specific to lists. > > ... which is built on top of c

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Guido van Rossum
Just trolling along, flattening a list could be written as functools.reduce(list.__iadd__, xs, []) Right? On Wed, Jun 16, 2021 at 22:53 David Mertz wrote: > On Thu, Jun 17, 2021, 1:38 AM Chris Angelico > >> >>> list(chain.from_iterable(list_of_lists)) >> >> > More-itertools has flatten(): >> h

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread David Mertz
Still an import for that version! On Thu, Jun 17, 2021, 2:07 AM Guido van Rossum wrote: > Just trolling along, flattening a list could be written as > > functools.reduce(list.__iadd__, xs, []) > > Right? > > On Wed, Jun 16, 2021 at 22:53 David Mertz wrote: > >> On Thu, Jun 17, 2021, 1:38 AM Chr

[Python-ideas] Re: Deprecate sum of lists

2021-06-16 Thread Chris Angelico
On Thu, Jun 17, 2021 at 4:07 PM Guido van Rossum wrote: > > Just trolling along, flattening a list could be written as > > functools.reduce(list.__iadd__, xs, []) > > Right? > Insufficiently trolly - lacks walrus operator. :) >>> l = [[1,2],[3,4],[5,6],[7,8],[9]] >>> any(map((x:=[]).extend, l))