I am writing my own parser for sheet music, just as an academic exercise for fun.
So, if I have a string, such as a chord progression:
In [1]: string = ' A D F#;m B;m F#;m'
and I'm interested in finding the string positions of each of the chords, I can do, for example:
In [3]: string.index('D')
Out[3]: 12
However, if I try finding the index of a repeated element, such as the F#;m
, the output will be:
In [4]: string.index('F#;m')
Out[4]: 15
However, there are two occurrences of F#;m, one at position 15, and one at position 34.
Is there some other way to record the position of each chord in the string, especially one that works when the same element is present in the string twice?