Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:58:53+00:00 2026-06-07T06:58:53+00:00

I have a list of lists and each list has a repeating sequence. I’m

  • 0

I have a list of lists and each list has a repeating sequence. I’m trying to count the length of repeated sequence of integers in the list:

list_a = [111,0,3,1,111,0,3,1,111,0,3,1] 

list_b = [67,4,67,4,67,4,67,4,2,9,0]

list_c = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,23,18,10]

Which would return:

list_a count = 4 (for [111,0,3,1])

list_b count = 2 (for [67,4])

list_c count = 10 (for [1,2,3,4,5,6,7,8,9,0])

Any advice or tips would be welcome. I’m trying to work it out with re.compile right now but, its not quite right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:58:55+00:00Added an answer on June 7, 2026 at 6:58 am

    Guess the sequence length by iterating through guesses between 2 and half the sequence length. If no pattern is discovered, return 1 by default.

    def guess_seq_len(seq):
        guess = 1
        max_len = len(seq) / 2
        for x in range(2, max_len):
            if seq[0:x] == seq[x:2*x] :
                return x
    
        return guess
    
    list_a = [111,0,3,1,111,0,3,1,111,0,3,1] 
    list_b = [67,4,67,4,67,4,67,4,2,9,0]
    list_c = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,23,18,10]
    
    print guess_seq_len(list_a)
    print guess_seq_len(list_b)
    print guess_seq_len(list_c)
    print guess_seq_len(range(500))   # test of no repetition
    

    This gives (as expected):

    4
    2
    10
    1
    

    As requested, this alternative gives longest repeated sequence. Hence it will return 4 for list_b. The only change is guess = x instead of return x

    def guess_seq_len(seq):
        guess = 1
        max_len = len(seq) / 2
        for x in range(2, max_len):
            if seq[0:x] == seq[x:2*x] :
                guess = x
    
        return guess
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of items. When I create the list each item has
I have a list of core data objects each has a longitude and latitude
I have a list of objects. Each object has an integer quantity and a
I have a list of Customers. Each customer has an address and some customers
I have a list of communities. Each community has a list of members. Currently
I have a list of articles, and each article has its own title and
I have a list called Countries, and each country has a list of Towns,
I have a list which contains dictionaries. Each dictionary has an attribute description which
I have a list view that displays a collection of items, each item has
I have a list of data that is a schedule. Each item has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.