fork download
  1. def get_new_index(oldindex, str):
  2. newindex = 0
  3.  
  4. for c in str:
  5. if c != '-':
  6. if oldindex == 0:
  7. return newindex
  8. oldindex -= 1
  9. newindex += 1
  10.  
  11. return 1 / 0 # should never get here
  12.  
  13. def printv(i, s):
  14. i = get_new_index(i, s)
  15. print(i, s[i])
  16.  
  17. str = "---------------LL---NE--HVKTHTEEK---PF-ICTVCR-KS----------"
  18.  
  19. # E's are located: ^ ^^
  20.  
  21. printv(12, str) # 1-indexed position of third E
  22. printv(11, str) # 0-indexed position of third E
  23. printv(0, str) # edge case test
  24. printv(1, str)
  25. printv(22, str) # edge case test
  26. # printv(23, str) # index is too high, error
Success #stdin #stdout 0.02s 5744KB
stdin
Standard input is empty
stdout
32 K
31 E
15 L
16 L
47 S