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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:11:04+00:00 2026-06-06T15:11:04+00:00

I found a function on the web that generates all sub-multisets of a set

  • 0

I found a function on the web that generates all sub-multisets of a set and then returns them. But as i walked the code through to understand what it actually does, i really got stuck.

Here’s the code:

def build_substrings(string):
    """ Returns all subsets that can be formed with letters in string. """
    result = []
    if len(string) == 1:
        result.append(string)
    else:
        for substring in build_substrings(string[:-1]):
            result.append(substring)
            substring = substring + string[-1]
            result.append(substring)
        result.append(string[-1])
    return result

Now, let’s say i call it with an arguement “ab”. The base case is ignored, so i get to the else block and call the function again, now the argument being “a”. I get to the base case and it appends “a” to result. now i return the result. the for loop is now ‘activated’. substring is assigned “a” and it is appended to the result list. Now, i have appended “a” two times to the list called ‘result’ . Somehow, in the output it is shown only once.
Thank you very much for your help.

  • 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-06T15:11:05+00:00Added an answer on June 6, 2026 at 3:11 pm

    Now, i have appended “a” two times to the list called ‘result.

    No, result is a local variable, and the first time you append “a” to it, it’s the local result of build_substrings("a") whereas the second time it’s the local result of build_substrings("ab"). They are two different calls to your method so they don’t share their result.

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

Sidebar

Related Questions

I found it in Jquery documentation that fadeOut() accepts callback function but in my
I found the following code in my team's project: Public Shared Function isRemoteDisconnectMessage(ByRef m
I've found some places on the web saying that operators in Lua are overloadable
I've found out that my web pages (mainly index.php, main.html, include.inc) have been injected
New to jQuery here. I've found several web pages that come close to what
I found this function that does an AWESOME job (IMHO): http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl /** * Get
I'm looking for a JavaScript function that given a string returns a compressed (shorter)
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I have a web form that does not call an action, but when submitted
In Matlab Function Alphabetical Reference I only found the following function: web - Open

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.