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 out of bound exceptions to reduce the number of lines necessary for error checking. Although negative indexing is one of those quintessential pythonic traits, Python's indexing schemes do require more base and edge cases to consider in implementation. I feel the feature should be conserved in the language, not in practice.

On Nov 24, 2020 2:36 PM, "Mathew M. Noel via Python-ideas" <python-ideas@python.org> 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 the 0th element. Consider a list with n elements: it would be perfectly reasonable to address the element 0 of the list using an index of n since n occurs after n-1 (if we assume that the list is bent into a circle). This feature can prove to be extremely useful. Consider the following example:


days_of_the_week = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]

It would be nice if
days_of_the_week[0]
is the same as
days_of_the_week[7] 

is the same as
days_of_the_week[14] etc

In other words use modular indexing.
In other words if the index is outside the range 0 to n-1, we simply take the remainder when the index is divided by n as the index.
Because of the close relationship between finite length sequences and periodic sequences this feature might simplify scientific computing(circular convolution etc).



_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/J43OCZG6LBQHJCGWAYJR3V4EGR66K22A/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to