Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countAndQuantify(substr,s) :
- count = 0
- occurrences = []
- for startIndex in range(len(s)-len(substr)):
- for relativeIndex in range(len(substr)):
- does_occur = True
- if s[startIndex+relativeIndex]!=substr[relativeIndex] :
- does_occur = False
- break
- if does_occur :
- distanceFromLast = -1
- if len(occurrences)>0 :
- distanceFromLast , _ = occurrences[len(occurrences)-1]
- occurrences += [[startIndex,distanceFromLast]]
- return occurrences,count
- occurrences,count = countAndQuantify('3AEFAE102','S3AEFAE102AFSGDGSHH3AEFAE102 HAJJSHH3AEFAE102BSJSBJS AJKE')
- print(count)
- print(occurrences)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement