[Python-ideas] Re: List .index() Method

2021-01-31 Thread Evpok Padding
On Fri, 29 Jan 2021 at 14:37, Francis O'Hara Aidoo wrote: > I understand that the same effect can be achieved with the index notation > - as in > if listy[-1] == 10: > print("Monty Python") > - but the way that came naturally to me was to use the .index method > rather than index notation, an

[Python-ideas] Re: List .index() Method

2021-01-29 Thread Greg Ewing
On 30/01/21 3:27 am, Francis O'Hara Aidoo wrote: listy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] if listy.index(10) == -1:   print("Monty Python") > Although ambiguity will make it difficult to implement, The difficulty isn't just with implementation, it's with *specification*. How is it

[Python-ideas] Re: List .index() Method

2021-01-29 Thread William Pickard
index is meant to return the index of the first match it finds in the list from the beginning, it's most simpless implementation is: ``` for i, v in enumerate(self): if v == value: return i throw ValueError(f"Value '{value}' is not in list") if you want the negative index, just