Python 3 Negative Indexes

2

So, folks. I am new to python and wanted to know the following:

Do you have any way of knowing what the negative index of an item in a list is?

For example, I have the following code:

lista = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
lista.index('a')
0
lista.index('g')
6

I would like to know if there is a method that returns the index backwards, like this:

lista.index('g')
-1
lista.index('a')
-7

I could not find anything like it.

    
asked by anonymous 12.09.2017 / 00:02

1 answer

0

According to @bfavaretto's comment, the answer is:

lista.index('a') - len(lista)
    
06.03.2018 / 13:47