Python Forum
detect equal sequences in list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
detect equal sequences in list
#7
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]]
Reply


Messages In This Thread
detect equal sequences in list - by flash77 - Oct-14-2022, 09:10 AM
RE: detect equal sequences in list - by Yoriz - Oct-14-2022, 10:28 AM
RE: detect equal sequences in list - by deanhystad - Oct-14-2022, 07:07 PM
RE: detect equal sequences in list - by flash77 - Oct-15-2022, 08:05 AM
RE: detect equal sequences in list - by deanhystad - Oct-15-2022, 12:05 PM
RE: detect equal sequences in list - by flash77 - Oct-15-2022, 09:10 PM
RE: detect equal sequences in list - by Pedroski55 - Oct-16-2022, 12:53 AM
RE: detect equal sequences in list - by DPaul - Oct-16-2022, 06:36 AM
RE: detect equal sequences in list - by flash77 - Oct-16-2022, 05:27 PM
RE: detect equal sequences in list - by flash77 - Oct-26-2022, 09:30 AM
RE: detect equal sequences in list - by flash77 - Oct-26-2022, 12:00 PM
RE: detect equal sequences in list - by deanhystad - Oct-26-2022, 05:43 PM
RE: detect equal sequences in list - by flash77 - Oct-27-2022, 06:53 AM
RE: detect equal sequences in list - by deanhystad - Oct-27-2022, 08:04 AM
RE: detect equal sequences in list - by flash77 - Oct-27-2022, 08:35 AM
RE: detect equal sequences in list - by flash77 - Oct-27-2022, 09:13 AM
RE: detect equal sequences in list - by deanhystad - Oct-27-2022, 03:56 PM
RE: detect equal sequences in list - by flash77 - Oct-28-2022, 06:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 947 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  Regarding how to randomizing list with having equal probability radraw 14 2,424 Nov-06-2022, 11:09 PM
Last Post: Pedroski55
  is there equal syntax to "dir /s /b" kucingkembar 2 1,069 Aug-16-2022, 08:26 AM
Last Post: kucingkembar
  Can a variable equal 2 things? Extra 4 1,589 Jan-18-2022, 09:21 PM
Last Post: Extra
  needleman wunsch algorithm for two sequences of different length johnny_sav1992 0 1,755 Jul-27-2020, 05:45 PM
Last Post: johnny_sav1992
  help for escape sequences NewPi 1 2,098 Dec-11-2019, 11:22 PM
Last Post: ichabod801
  Not equal a dictionary key value bazcurtis 2 1,997 Dec-11-2019, 11:15 PM
Last Post: bazcurtis
  copying parts of mutable sequences Skaperen 1 2,308 Dec-02-2019, 10:34 AM
Last Post: Gribouillis
  Convert weekly sequences to date and time. SinPy 0 1,514 Nov-23-2019, 05:20 PM
Last Post: SinPy
  Escape sequences display in python Uchikago 1 2,509 Jun-27-2019, 03:25 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020