fork download
  1. # your code goes here
  2. def takeIndex (str, c, index):
  3. count = 0
  4. for i in range(len(str)):
  5. if (str[i] == c):
  6. count += 1
  7. if (count == index):
  8. return i
  9. if (count == 0):
  10. return -1
  11.  
  12. a = "quan tri mang cham com"
  13. print (takeIndex(a, 'a', 2))
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
10