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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:58:08+00:00 2026-05-18T08:58:08+00:00

although there’s quite a bit of information about recursion on the web, I haven’t

  • 0

although there’s quite a bit of information about recursion on the web, I haven’t found anything that I was able to apply to my problem. I am still very new to programming so please excuse me if my question is rather trivial.

Thanks for helping out 🙂

This is what I want to end up with:

listVariations(listOfItems, numberOfDigits) 

>>> listVariations(['a', 'b', 'c'], 1)
>>> ['a', 'b', 'c'] 

>>> listVariations(['a', 'b', 'c'], 2)
>>> ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']

>>> listVariations(['a', 'b', 'c'], 3)
>>> ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc']

but so far I was only able to come up with a function where I need to specify/know the number of digits in advance. This is ugly and wrong:

list = ['a', 'b', 'c']

def listVariations1(list):
  variations = []
  for i in list:
    variations.append(i)
  return variations

def listVariations2(list):
  variations = []
  for i in list:
    for j in list:
      variations.append(i+j)
  return variations

def listVariations3(list):
  variations = []
  for i in list:
    for j in list:
      for k in list:
        variations.append(i+j+k)
  return variations

oneDigitList = listVariations1(list)
twoDigitList = listVariations2(list)
threeDigitList = listVariations3(list)

This is probably very easy, but I couldn’t come up with a good way to concatenate the strings when the function calls itself.

Thanks for your effort 🙂

  • 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-05-18T08:58:09+00:00Added an answer on May 18, 2026 at 8:58 am

    You can use the product() function in itertools

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

Sidebar

Related Questions

Although there are a lot of posts about .net config files, I believe that
Although there are quite a lot of Q&As regarding IDisposable to be found on
I'm building a site using CodeIgniter that largely consists of static content (although there
Although the question title appears a bit subjective I am sure there is not
Although appengine already is schema-less, there still need to define the entities that needed
!!IMPORTANT!! Solution found, you need to use a sql.timestamp. Although there are 2 problems
I'm almost finished with my project, although there is one thing that I can't
Ok! I have to say both technology are great. Although there seems that something
Although there are many tutorials out there, I've found it really difficult to implement
Although there are plenty of unit test frameworks that support C, I'm a little

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.