Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from string import *
- key_s = raw_input("Enter the string you want to search. > ")
- target_s = raw_input("Enter what you are searching for. > ")
- def count_sub_string_match(key_s, target_s):
- x = find(key_s, target_s)
- iter_counter = 0
- while x >= 0:
- key_s = key_s[x+1:]
- iter_counter += 1
- x = find(key_s, target_s)
- return iter_counter
- recur_counter = 0
- def count_sub_string_match_recursive(key_s, target_s):
- x = find(key_s, target_s)
- if x >= 0:
- global recur_counter
- recur_counter += 1
- count_sub_string_match_recursive(key_s[x+1:], target_s)
- return recur_counter
- print "This is how many times it shows up.", count_sub_string_match(key_s, target_s)
- print "This is how it looks recursively.", count_sub_string_match_recursive(key_s, target_s)
Advertisement
Add Comment
Please, Sign In to add comment