0

I tried the following code

s = "BANANA"
print(s.count('ANA'))
>> 1

The output was 1. It did not consider A which was previously counted. I want the output to be 2 since 'ANA' occurs twice. Ia their a function I don't know about.

Arjun Kashyap
  • 337
  • 1
  • 2
  • 7
  • If you want to count the length of the string, just do: `print( len(s) )` If you want to count 'ANA', just do `print(len('ANA'))` – its.david Dec 06 '17 at 14:39
  • 1
    I dont think you Understood my question. I want to check how many times the substring (Here: 'ANA') occurs between the string. Or How any times 'ANA' appears in the word 'BANANA ' @ezzzCash – Arjun Kashyap Dec 06 '17 at 15:59
  • Ohh I understand now. your question is very similar to a more complex question that I asked a few days ago. The only difference is my question is dealing with integers rather than strings. However, the logic is still the same. Please the answer located here: https://stackoverflow.com/questions/47581326/given-a-string-of-a-million-numbers-return-all-repeating-3-digit-numbers – its.david Dec 06 '17 at 16:03

0 Answers0