Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- perms = ["ab", "cd", "ef"]
- string ="asdansdkjajskdnklabklmkalabmkklmabcdkmlabcdefkmlkm"
- def findPerm(li):
- lowerFound = 0
- upperFound = 0
- foundItems = []
- # loop through the whole string - length of the first item
- for i in range(0,len(string)-len(li[0])):
- # if the first item is found, begin searching for the rest
- if(string[i:i+len(li[0])] == li[0]):
- foundItems = [0]
- lowerFound = i
- upperFound = i+len(li[0])
- found = 0
- # try to find all elements of the permutation
- while found < len(foundItems):
- found = len(foundItems)
- # search for 1 element of the permutation either before or after the found permutation
- for i in range(0,len(li)):
- if(i not in foundItems):
- if(string[lowerFound-len(li[i]):lowerFound] == li[i]):
- lowerFound -= len(li[i])
- foundItems.append(i)
- break
- if(string[upperFound:upperFound+len(li[i])] == li[i]):
- upperFound += len(li[i])
- foundItems.append(i)
- break
- if(len(foundItems) == len(li)):
- return lowerFound, upperFound
- return 0,0
- print(findPerm(perms))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement