jprichter

ps3a

Oct 17th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from string import *
  2.  
  3. key_s = raw_input("Enter the string you want to search. > ")
  4. target_s = raw_input("Enter what you are searching for. > ")
  5.  
  6. def count_sub_string_match(key_s, target_s):
  7.     x = find(key_s, target_s)
  8.     iter_counter = 0
  9.     while x >= 0:
  10.         key_s = key_s[x+1:]
  11.         iter_counter += 1
  12.         x = find(key_s, target_s)
  13.     return iter_counter
  14.  
  15. recur_counter = 0
  16.  
  17. def count_sub_string_match_recursive(key_s, target_s):
  18.     x = find(key_s, target_s)
  19.     if x >= 0:
  20.         global recur_counter
  21.         recur_counter += 1
  22.         count_sub_string_match_recursive(key_s[x+1:], target_s)
  23.     return recur_counter
  24.    
  25. print "This is how many times it shows up.", count_sub_string_match(key_s, target_s)
  26. 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