Advertisement
vaboro

ps3b.py

May 25th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. import string
  2.  
  3. def subStringMatchExact(target, key):
  4.     positions_list = []
  5.     position = string.find(target, key)
  6.     if key != "":
  7.         while position != -1:
  8.             positions_list.append(position)
  9.             position = string.find(target, key, position + len(key))
  10.     else:
  11.         for i in range(len(target)):
  12.             positions_list.append(i)
  13.     positions_tuple = tuple(positions_list)
  14.     return positions_tuple
  15.  
  16. def subStringMatchExactRecursive(target, key, positions, index):
  17.     position = string.find(target, key, index)
  18.     if key != "":
  19.         if position != -1:
  20.             positions.append(position)
  21.             subStringMatchExactRecursive(target, key, positions, position+len(key))
  22.     else:
  23.         for i in range(len(target)):
  24.             positions.append(i)
  25.     positions = tuple(positions)
  26.     return positions
  27.  
  28. ##target1 = 'atgacatgcacaagtatgcat'
  29. ##target2 = 'atgaatgcatggatgtaaatgcag'
  30. ##
  31. ### key strings
  32. ##
  33. ##key10 = 'a'
  34. ##key11 = 'atg'
  35. ##key12 = 'atgc'
  36. ##key13 = 'atgca'
  37. ##
  38. ##print subStringMatchExact(target1, key10)
  39. ##print subStringMatchExact(target1, key11)
  40. ##print subStringMatchExact(target1, key12)
  41. ##print subStringMatchExact(target1, key13)
  42. ##print subStringMatchExact(target2, key10)
  43. ##print subStringMatchExact(target2, key11)
  44. ##print subStringMatchExact(target2, key12)
  45. ##print subStringMatchExact(target2, key13)
  46. ##print
  47. ##print subStringMatchExactRecursive(target1, key10,[],0)
  48. ##print subStringMatchExactRecursive(target1, key11,[],0)
  49. ##print subStringMatchExactRecursive(target1, key12,[],0)
  50. ##print subStringMatchExactRecursive(target1, key13,[],0)
  51. ##print subStringMatchExactRecursive(target2, key10,[],0)
  52. ##print subStringMatchExactRecursive(target2, key11,[],0)
  53. ##print subStringMatchExactRecursive(target2, key12,[],0)
  54. ##print subStringMatchExactRecursive(target2, key13,[],0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement