Hello, On Tue, 24 Nov 2020 19:36:03 +0000 "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. No. > 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. If you want to use modular indexing, do exactly that: days_of_the_week[7 % 7] days_of_the_week[14 % 7] days_of_the_week[foo % 7] As was already mentioned, you can even hide that behind a 'list' subclass. -- Best regards, Paul mailto:pmis...@gmail.com _______________________________________________ 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/B2OO6Q7CCJDWLI2PHXCG3L4EISXTFQ6Y/ Code of Conduct: http://python.org/psf/codeofconduct/