Oct-16-2022, 12:53 AM
(This post was last modified: Oct-16-2022, 12:53 AM by Pedroski55.)
Quote:Hanging position is: 1 to 3 and 5 to 8
As I understand it, you want the positions of the beginning and end of sequences of the same number in the list hash_list_film.
I don't understand what you are using hash for, maybe you are hashing a tuple?? But that wouldn't make a difference.
sequences is a list of lists of the start position of a sequence of the same number and the end position + 1
Thus, you could take each sub-list and loop through the numbers that are the same and do whatever you wish.
If hash_list_film ends with a sequence, that makes things awkward for my little function, so just append an X anyway.
What you do with the data in sequences is up to you!
def myApp(): hash_list_film = ["12", "11", "11", "11", "17", "22", "22", "22", "22", "23", "24", "24", "24", "24" "X"] sequences = [] count = 0 def getSequence(start): tmp = [start] for k in range(start + 1, len(hash_list_film)-1): # bale out of k loop at end of sequence if hash_list_film[k] != hash_list_film[k+1]: tmp.append(k+1) sequences.append(tmp) return k+1 while count < len(hash_list_film) - 1: print(count) if hash_list_film[count] == hash_list_film[count+1]: count = getSequence(count) elif hash_list_film[count] != hash_list_film[count+1]: count +=1 print(sequences)
Output:[[1, 4], [5, 9], [10, 13]]