[Tutor] Help with writing a program

Steven D'Aprano steve at pearwood.info
Mon Dec 3 11:17:43 CET 2012


On 03/12/12 14:59, rajesh mullings wrote:
> Hello, I am trying to write a program which takes two lines of input, one
> called "a", and one called "b", which are both strings, then outputs the
> number of times a is a substring of b. If you could give me an
> algorithm/pseudo code of what I should do to create this program, I would
> greatly appreciate that. Thank you for using your time to consider my
> request.

Are you talking about something like this?

a = "ing"
b = """\
Our ingenious plan worked, and the Laughing Prince, last seen capering
madly while his Motley Monks sat gibbering, was soon vanquished, though
not without some achingly painful experiences.
"""

count(b, a)

=> should return 5


If that is what you want, try reading the Fine Manual about string methods,
and you can count on finding something to help solve this problem.

https://duckduckgo.com/?q=python%20string%20methods



-- 
Steven


More information about the Tutor mailing list