0

I am trying to find the index of last occurrence of a particular character in a string.

eg: s = [1,2,3,4,2,4,5,4]

in the above string I need to find the index of '4' that was situated last in the string. could anyone help me out in this?

Thank you

  • 1
    That's a list of integers, not a string. Strings have a method `rfind` that does what you're looking for. – bgporter Apr 18 '14 at 00:06

1 Answers1

-1

Get the length which tells how many items are in your list (8) and minus one because indices start at 0 (0-7)

s = [1,2,3,4,2,4,5,4]

f = len(s) - 1

print f
print s[f]
Christopher Reid
  • 4,318
  • 3
  • 35
  • 74