Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am unable to understand this problem....please make me understand and write a program to solve this question

What I have tried:

I don't have idea how to tackle this question.
Posted
Updated 10-Feb-23 23:07pm

Start be reading the assignment carefully - it may be different from the "summary" you gave us.
You need to find all the times that a string occurs inside another. So if you are looking for all occurrences of "hello" in "hello Mike, hello Jane, hello Peter" it would be there three times: "hello Mike, hello Jane, hello Peter" and the indices are the number of characters from the start of the string at which the substring appears:
hello Mike, hello Jane, hello Peter
^           ^           ^
|           |           |
|           |            --- 24
|            --- 12
--- 0
Then ask yourself "How would I do this manually?".
You would look through the string looking for the "h" and checking if it was followed by an "e", then an "l", and so on. If it was, you've found a substring, so make a note of the start position.
Either way, you'd then move on to the next character and check again.

Work out in your head exactly what rules you need to follow, and try them out manually on several different strings and substrings. When you have rules that cover all the cases you can think of (including empty strings, whole matches, no matches, etc.) then think about how to computerise them.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
See Built-in Types — Python 3.10.10 documentation[^] for information on using and accessing strings.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900