Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- def subStringMatchExact(target, key):
- positions_list = []
- position = string.find(target, key)
- if key != "":
- while position != -1:
- positions_list.append(position)
- position = string.find(target, key, position + len(key))
- else:
- for i in range(len(target)):
- positions_list.append(i)
- positions_tuple = tuple(positions_list)
- return positions_tuple
- def subStringMatchExactRecursive(target, key, positions, index):
- position = string.find(target, key, index)
- if key != "":
- if position != -1:
- positions.append(position)
- subStringMatchExactRecursive(target, key, positions, position+len(key))
- else:
- for i in range(len(target)):
- positions.append(i)
- positions = tuple(positions)
- return positions
- ##target1 = 'atgacatgcacaagtatgcat'
- ##target2 = 'atgaatgcatggatgtaaatgcag'
- ##
- ### key strings
- ##
- ##key10 = 'a'
- ##key11 = 'atg'
- ##key12 = 'atgc'
- ##key13 = 'atgca'
- ##
- ##print subStringMatchExact(target1, key10)
- ##print subStringMatchExact(target1, key11)
- ##print subStringMatchExact(target1, key12)
- ##print subStringMatchExact(target1, key13)
- ##print subStringMatchExact(target2, key10)
- ##print subStringMatchExact(target2, key11)
- ##print subStringMatchExact(target2, key12)
- ##print subStringMatchExact(target2, key13)
- ##print
- ##print subStringMatchExactRecursive(target1, key10,[],0)
- ##print subStringMatchExactRecursive(target1, key11,[],0)
- ##print subStringMatchExactRecursive(target1, key12,[],0)
- ##print subStringMatchExactRecursive(target1, key13,[],0)
- ##print subStringMatchExactRecursive(target2, key10,[],0)
- ##print subStringMatchExactRecursive(target2, key11,[],0)
- ##print subStringMatchExactRecursive(target2, key12,[],0)
- ##print subStringMatchExactRecursive(target2, key13,[],0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement