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

  • Home
  • SEARCH
  • 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 7823429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:14:37+00:00 2026-06-02T08:14:37+00:00

I wrote a function to return a generator containing every unique combination of sub-strings

  • 0

I wrote a function to return a generator containing every unique combination of sub-strings a given length that contain more than n elements from a primary string.

As an illustration:

if i have ‘abcdefghi’ and a probe of length of two, and a threshold of 4 elements per list i’d like to get:

['ab', 'cd', 'ef', 'gh']
['ab', 'de', 'fg', 'hi']
['bc', 'de', 'fg', 'hi']

My first attempt at this problem involved returning a list of lists. This ended up overflowing the memory of the computer. As a crude secondary solution, I created a generator that does something similar. The problem is that I created a nested generator that calls itself. When I run this function, it seems to just loop around the inner for loop without actually calling itself again. I thought that a generator would precede as far down the recursion hole as necessary until it hit the yield statement. Any clue what is happening?

def get_next_probe(self, current_probe_list, probes, unit_length):
    if isinstance(current_probe_list, list):
        last_probe=current_probe_list[-1]
        available_probes = [candidate for candidate in probes if candidate.start>last_probe.end]
    else:
        available_probes = [candidate for candidate in probes if candidate.start<unit_length]

    if available_probes:

        max_position=min([probe.end for probe in available_probes])
        available_probes2=[probe for probe in available_probes if max_position+1>probe.start]

        for new_last_probe in available_probes2:
            new_list=list(current_probe_list)
            new_list.append(new_last_probe)
            self.get_next_probe(new_list, probes, unit_length)

    else:
        if len(current_probe_list)>=self.num_units:
            yield current_probe_list

If yield is changed to print this works just fine! I’d appreciate any help I could get. I realize this isn’t an optimal implementation of this type of search problem, it seems like returning a list of found positions from the last call of get_next_probe and filtering this list for the elements that do not overlap new_last_probe.end would be far more efficient… but this was a lot easier for me to write. Any algorithm input would still be appreciated.

Thanks!

  • 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-02T08:14:39+00:00Added an answer on June 2, 2026 at 8:14 am

    I thought that a generator would precede as far down the recursion hole as necessary until it hit the yield statement

    It will recurse fine, but to get the yielded value to propogate back outward, you need to do it explicitly – just like if it was a return, you would need to explicitly return the result of each recursion. So, instead of:

     self.get_next_probe(new_list, probes, unit_length)
    

    You would do something like:

     for val in self.get_next_probe(new_list, probes, unit_length):
         yield val
    

    Or if you’re using Python 3.3 or newer, you can also do this:

    yield from self.get_next_probe(new_list, probes, unit_length)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a function in Python: def instantiate(c): if inspect.isclass(c): return c() elif isinstance(c,
i wrote a simple function in controller public string LinkProjectSquareFilter(int squareId) { return squareId.ToString();
How can I write a function which will return pi (π) to a given
I'm trying to write a function that will return all the available cars for
i am trying to write a function that will make DataRow[column] return nullable typed
I am trying to write a function that will randomly return an (x,y) co-ordinates
When I read some question to write random nuber generator ,I saw that function
I wrote a class that builds some url in a page every time there
I wrote this function that creates a random string of UTF-8 characters. It works
i am trying to write one function which return sql statement like function get_sql($name=0,$date_start=0,$date_end=0)

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.