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 8802465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:05:46+00:00 2026-06-14T01:05:46+00:00

For two days I have been researching for this and have not found anything

  • 0

For two days I have been researching for this and have not found anything so I decided to write my own string repetition detector. Basically the function

def findRepetitions (string):

would receive a string and search for any repetitions; returns a list of strings reduced to their simplest form.

For a sample, it’d be:

findRepetitions ("trololololo") --> ["olo"]
findRepetitions ("bookkeeper") ---> ["o", "k", "e"]
findRepetitions ("Hello, Molly") -> ["l", "l"]
findRepetitions ("abcdefgh") -----> []
findRepetitions ("102102102") ----> ["102"]

In the third example, the function returns [“l”, “l”] instead of [“ll”], because I want to search for repetitions only in the neighboring characters.

I know that this may be hard, but I’ve been literally thinking over this for a long time and cannot find any smart solution to this.

  • 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-14T01:05:46+00:00Added an answer on June 14, 2026 at 1:05 am

    Your examples are inconsistent. For example, olo does not repeat, like the l in Hello, Molly, in `trololololo; there’s an l between instances. Sequential repeats in trololololo are lolo, lo, olol, and ol. Are you asking for a ‘greedy’ algorithm? So, given trololololo, it would return olol?

    In any case, here’s a bit of code.

    from collections import Counter
    
    def find_repetition(p):
        """ Returns a lookup dictionary for repetitions. """ 
        lookup = Counter()
        while len(p) != 0:
            for i in xrange(len(p)):
                lookup[p[0:i]] += 1
            p = p[1:]
        return lookup
    
    def repeats(p):
        a = find_repetition(p)
        rs = [i for i in a if a[i] > 1][1:]
        return [r for r in rs if r*2 in p]
    

    If you want it to be ‘greedy’ like I described, you have to add in another function that takes the results from repeats and chomps away at your string when it finds a match.

    For now, the results look like this:

    test = "trololololo", "bookkeeper", "Hello, Molly", "abcdefgh", "102102102"
    
    >>> for i in test:
    >>>     repeats(i)
    
    ['lolo', 'lo', 'olol', 'ol']
    ['e', 'o', 'k']
    ['l']
    []
    ['210', '021', '102']
    

    warning

    find_repetition is not very quick, since it basically generates all length combinations of the string and throws them into a Counter object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working at this for two days and have not had much luck.
I have been trying this from two days but unable to found a solution
Have been fighting this for two days and am very frustrated but feel like
I have been researching this topic for a few days now and i'm still
I have been searching for this for the pass two days .I am developing
I have been researching the answer to my question for two days now and
This topic has been covered over and over, but after two days of researching
I have been searching for two days and have not been able to find
I have been banging my head of the wall for two days with this
I have been working on this for about two days....I have a RadioButtonList that

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.