Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1.  
  2. def countAndQuantify(substr,s) :
  3.         count = 0
  4.         occurrences = []
  5.         for startIndex in range(len(s)-len(substr)):
  6.                 for relativeIndex in range(len(substr)):
  7.                         does_occur = True
  8.                         if s[startIndex+relativeIndex]!=substr[relativeIndex] :
  9.                                 does_occur = False
  10.                                 break
  11.  
  12.                 if does_occur :
  13.                         distanceFromLast = -1
  14.                         if len(occurrences)>0 :
  15.                                 distanceFromLast , _ = occurrences[len(occurrences)-1]
  16.                         occurrences += [[startIndex,distanceFromLast]]
  17.         return occurrences,count
  18.  
  19.  
  20. occurrences,count = countAndQuantify('3AEFAE102','S3AEFAE102AFSGDGSHH3AEFAE102 HAJJSHH3AEFAE102BSJSBJS AJKE')
  21. print(count)
  22. print(occurrences)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement