-1

I want to find number of times a string present in a string in python

i already tried

my_str = "Hello world all in the world call me tell me"
sum(1 for x in my_str if x="ll")

i want its result as 4

matino
  • 17,199
  • 8
  • 49
  • 58
Bamaboy
  • 229
  • 1
  • 4
  • 13
  • check this: http://stackoverflow.com/questions/4664850/find-all-occurrences-of-a-substring-in-python – Jordi Castilla Jan 30 '15 at 13:24
  • 1
    How many `'ll'`s are there in `'Schalllampe'`? – eumiro Jan 30 '15 at 13:28
  • 1
    @eumiro asked the right question: you could argue for an answer of 0 in his example (because there's no `ll` which isn't unambiguously separated), or 1 (because we don't allow overlaps), 2 (because we *do* allow overlaps), or even 3, though it's a stretch (because we allow you to skip internal duplicates in a group). – DSM Jan 30 '15 at 13:34

1 Answers1

0

You can use string count method:

my_str.count('ll')
matino
  • 17,199
  • 8
  • 49
  • 58