[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Paul Sokolovsky
Hello, On Tue, 24 Nov 2020 19:36:03 + "Mathew M. Noel via Python-ideas" wrote: > Python uses an index of -1 to index the last element in a list. Since > -1 occurs before 0 we might think of the elements of the linear list > are being bent into a circle making the last element occur before th

[Python-ideas] Re: Circular Indexing and FOR loop minimization

2020-11-25 Thread Steven D'Aprano
Hi Mathew, welcome! My responses interleaved with your comments. On Wed, Nov 25, 2020 at 04:29:17AM +, Mathew M. Noel via Python-ideas wrote: > As discussed earlier on the post on 'Circular Indexing', considering > interpreting indices that lie outside the range 0 to n-1 modulo n for > li

[Python-ideas] async types?

2020-11-25 Thread Ben Avrahami
Hi all, this is a general feeler for if this idea has any traction: All too often I see the following pattern in asyncio 3rd-party libs, either in their own source code or in the inusage: ``` inst = SomeClass() await inst.initialize() ``` What happens here is that, since coroutines cannot be used

[Python-ideas] Re: Circular Indexing and FOR loop minimization

2020-11-25 Thread Serhiy Storchaka
25.11.20 06:29, Mathew M. Noel via Python-ideas пише: > 2.) If circular indexing is used then instead of using a double FOR loop > to go through a loop twice we can iterate from 0 to 2n ! If you just need to iterate list indices twice, iterate range(-n, n) instead of range(n).

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread nathan . w . edwards
The power in programming is the simplicity in keyword and instruction function, I do believe. As much as I love the concept, I feel the use of a data structure to handle such cases circular indexing is needed is more appropriate than changing loop statement behavior.At times I heavily rely on index

[Python-ideas] Getting rid of FOR loops and simplifying cicular conviolutions with Circular Indexing

2020-11-25 Thread Mathew M. Noel via Python-ideas
If circular indexing is used then instead of using a double FOR loop to go through a list M times we can iterate from 0 to M*N (where N is the length of the list) !!! Almost all Machine Learning (ML) algorithms iterate for some predefined epochs over a large data-set. So a double FOR loop is e

[Python-ideas] Re: async types?

2020-11-25 Thread Joao S. O. Bueno
A while back I could make a proof of concept of this with current Python, no modifications needed. The text is in portuguese -by I believe automatic translation should be enough for the non-code parts. https://pt.stackoverflow.com/questions/390755/%c3%89-poss%c3%advel-definir-como-async-o-m%c3%a9

[Python-ideas] Re: Getting rid of FOR loops and simplifying cicular conviolutions with Circular Indexing

2020-11-25 Thread Antoine Rozo
So why don't you implement your own type/wrapper with the semantics you need? Le mer. 25 nov. 2020 à 18:49, Mathew M. Noel via Python-ideas a écrit : > > If circular indexing is used then instead of using a double FOR loop to go > through a list M times we can iterate from 0 to M*N (where N is t

[Python-ideas] Re: Getting rid of FOR loops and simplifying cicular conviolutions with Circular Indexing

2020-11-25 Thread Calvin Spealman
days_of_the_week[14 % 7] There ya go! On Wed, Nov 25, 2020 at 12:51 PM Mathew M. Noel via Python-ideas < python-ideas@python.org> wrote: > If circular indexing is used then instead of using a double FOR loop to > go through a list M times we can iterate from 0 to M*N (where N is the > length of

[Python-ideas] Re: Getting rid of FOR loops and simplifying cicular conviolutions with Circular Indexing

2020-11-25 Thread David Mertz
You've started three separate threads to propose something that has exactly zero chance of happening, and would be of limited use in uncommon cases. And that would break literally billions of lines of working code. If you want the modulo operator, you are more than welcome to use it. If you want t

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Greg Ewing
On 26/11/20 2:30 am, nathan.w.edwa...@outlook.com wrote: At times I heavily rely on index out of bound exceptions to reduce the number of lines necessary for error checking. This is a downside to the negative indexing scheme -- you can't tell the difference between a backwards index and an erro

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Steven D'Aprano
On Thu, Nov 26, 2020 at 12:07:56PM +1300, Greg Ewing wrote: > On 26/11/20 2:30 am, nathan.w.edwa...@outlook.com wrote: > >At times I heavily rely on index out of bound exceptions to reduce the > >number of lines necessary for error checking. > > This is a downside to the negative indexing scheme

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Eric Fahlgren
On Wed, Nov 25, 2020 at 3:44 PM Steven D'Aprano wrote: > Obviously you can tell the two apart, so I'm confused by your comment. > What I imagined while reading Greg's comment was trying to explain to a student why this didn't work the way they expected. "Ok, so in the first case I'm *not* start

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Eric V. Smith
On 11/25/2020 6:41 PM, Steven D'Aprano wrote: On Thu, Nov 26, 2020 at 12:07:56PM +1300, Greg Ewing wrote: On 26/11/20 2:30 am, nathan.w.edwa...@outlook.com wrote: At times I heavily rely on index out of bound exceptions to reduce the number of lines necessary for error checking. This is a do

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Greg Ewing
On 26/11/20 12:41 pm, Steven D'Aprano wrote: a = "abcdef" a[-2] # returns a result Yes, but did you *intend* that result, or did the -2 result from a calculation that should have returned a positive index but went wrong? Python has no way to tell. -- Greg ___

[Python-ideas] Re: Getting rid of FOR loops and simplifying cicular conviolutions with Circular Indexing

2020-11-25 Thread Mathew M. Noel via Python-ideas
Why not use list_name[-n%N] whenever you need to use negative indices and raise an index out of bounds exception with negative indices like other programming languages? From: Calvin Spealman Sent: Thursday, November 26, 2020 1:00 AM To: Mathew M. Noel Cc: pyt

[Python-ideas] Re: Making the for statement work better with nested functions

2020-11-25 Thread Guido van Rossum
Hmm... In the end I think the language design issue is with functions (and how they capture variable references rather than values), and fixing it by changing the for-loop is still just a band-aid, with other problems and inconsistencies. Agreed that the fix 'x=x' essentially always works, and that

[Python-ideas] Re: Getting rid of FOR loops and simplifying cicular conviolutions with Circular Indexing

2020-11-25 Thread Antoine Rozo
Because it's not backward-incompatible with the behaviour of positive indices. Le jeu. 26 nov. 2020 à 05:56, Mathew M. Noel via Python-ideas < python-ideas@python.org> a écrit : > > Why not use list_name[-n%N] whenever you need to use negative indices and > raise an index out of bounds exception

[Python-ideas] Re: Circular Indexing

2020-11-25 Thread Paul Sokolovsky
Hello, On Thu, 26 Nov 2020 13:27:46 +1300 Greg Ewing wrote: > On 26/11/20 12:41 pm, Steven D'Aprano wrote: > > a = "abcdef" > > a[-2] # returns a result > > Yes, but did you *intend* that result, or did the -2 > result from a calculation that should have returned a > positive index