Advertisement
Guest User

Untitled

a guest
May 29th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. def calculate(k, phrase, text):
  4.     result = []
  5.     for start in range(len(text)):
  6.         to_compare = ''
  7.         for phrase_index in range(len(phrase)):
  8.             if start + phrase_index * k < len(text):
  9.                 to_compare += text[start + phrase_index * k]
  10.         print str(start) + ' ' + phrase + '!=' + to_compare
  11.         if phrase == to_compare:
  12.             result.append({'start': start, 'k' : k, 'phrase': phrase})
  13.     return result
  14.  
  15. text = u'zbadawszyplikeksperciorzekli'
  16. phrase = u'pies'
  17.  
  18. result = calculate(k=2, phrase=phrase, text=text)
  19. print result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement