Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/santosh2702/find-a-string
solution
https://github.com/santosh2702/find-a-string
python3
Last synced: 14 days ago
JSON representation
solution
- Host: GitHub
- URL: https://github.com/santosh2702/find-a-string
- Owner: santosh2702
- Created: 2018-06-03T14:33:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-13T18:12:04.000Z (over 6 years ago)
- Last Synced: 2024-11-06T19:33:44.400Z (2 months ago)
- Topics: python3
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Find-a-string
In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.
### NOTE: String letters are case-sensitive.
### Input Format
The first line of input contains the original string. The next line contains the substring.
### Constraints
1<=len(string)<=200
Each character in the string is an ascii character.
### Output Format
Output the integer number indicating the total number of occurrences of the substring in the original string.
### Sample Input
ABCDCDC
CDC
#Sample Output
2
### SOLTUTION
import re
word=input()
substr=input()
print(len([m.start() for m in re.finditer('(?='+substr+')', word)]))