Skip to content

Instantly share code, notes, and snippets.

@starwarsgeek1138
Last active June 16, 2016 21:18
Show Gist options
  • Save starwarsgeek1138/3c42e07dc30ad828f860c3e1d3bcab3b to your computer and use it in GitHub Desktop.
Save starwarsgeek1138/3c42e07dc30ad828f860c3e1d3bcab3b to your computer and use it in GitHub Desktop.
Python code to find looping subset within a tuple
##Finds looping subsets within a progression of chords, listed as a tuple (lick); outputs loop (as tuple) and # of repetitions within lick
def findLoops(lick):
lickLen = len(lick)
for i in range(1, lickLen - 1):
testLoop = lick[0:i] #find loop to test as subset
loopLen = len(lick[0:i]) #find test loop length
testVal = int(lickLen/loopLen) #find divisor, rounded down
testValRem= lickLen%loopLen #find remainder
if lick == (testLoop * testVal) + testLoop[0:testValRem]: # if lick = a multiple of the loop (including remainder), then loop is valid loop
loop = lick[0:i]
repeats = lickLen/float(loopLen)
break
else:
loop = lick
repeats = 1
return loop, repeats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment