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,861
  • 3
  • 7
  • 26
Serket
  • 2,769
  • 2
  • 11
  • 32

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
  • 40,932
  • 8
  • 45
  • 77