0

How can I find the positive index of myList[-1]?
This is an example of what I want:

Input:

myList = [1, 2, 3, 4, 3]
# Please keep in mind that the list can have multiple values that are the same

myIndex = # Find out the positive index of myList[-1] and store in myIndex variable
print(myIndex)

Desired Output:

4
ywbaek
  • 2,971
  • 3
  • 9
  • 28
Serket
  • 3,785
  • 3
  • 14
  • 45

1 Answers1

2

Well, it is:

myList = [1, 2, 3, 4, 3]
index = len(myList) - 1

You might want to check if it is greater or equal to zero.

Jan
  • 42,290
  • 8
  • 54
  • 79