How to count the total characters between two occurrences of specific character in string with Python

1 Answer

0 votes
s = 'python java python'
  
ch = 'p'

result = s.index(ch, s.index(ch) + 1) - s.index(ch) 
  
print(result)   
 
 
 
'''
run:
  
12
         
'''

 



answered May 11, 2020 by avibootz
...