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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:43:51+00:00 2026-06-10T12:43:51+00:00

Having spent a considerable amount of time now trying to come up with a

  • 0

Having spent a considerable amount of time now trying to come up with a way to (what I think) should be a relatively simple procedure, I have managed to write the code which will generate the results (thanks to suggestions on this wonderful forum!), but according to my calculations it would take several years to compute all possibilities, so I’m desperately looking for some help as I fear my computer may not live to see that day. 🙂 Any input would be very much appreciated!

What I would like to achieve is from a list of 10 unique entries (e.g. [‘A’,’B’,’C’,’D’,’E’,’F’,’G’,H’,’I’,’J’]), get all permutations over a string length of 10, but with the requirement that 1 of the elements (e.g. ‘C’), should occur exactly 3 times, and in all possible locations.

Right now I am using:

options = ['A','B','C','D','E','F','G','H','I','J']
def combos(options,n):
    if (n <= 0): return
    for s in options:
        if len(s) <= n: yield s
        for t in combos(options,n-len(s)): yield s+t

for x in combos(options,10):
    if x.count("C") == 3 and len(x) == 10:
        print x

This way, it is computing all possible permutations and picks the ones with 3 ‘Cs’, and therefore generates a large amount of unnecessary permutations which do not contain 3 ‘Cs’, hence why it is taking longer than necessary. Does anyone have any suggestions how I might get Python to adhere to the 3x ‘C’ restriction while generating the permutations?

many, many thanks in advance!

  • 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-10T12:43:53+00:00Added an answer on June 10, 2026 at 12:43 pm

    What BrenBarn proposes can give this:

    from itertools import product, combinations
    
    otheroptions = ['A','B',   'D','E','F','G','H','I','J']
    c = "C"
    l = 10
    nc = 3
    
    for t in product(otheroptions, repeat=l-nc):
        for p in combinations(range(l), nc):
            r = list(t)
            for i in p:
                r[i:i] = [c]
            print "".join(r)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to MVC3 Razor - linq to sql having spent some time trying to
I have been having a terrible time trying to compile a python extension -
I have spent hours trying to find an answer to this, and have come
Having spent some time working on data warehousing, I have created both ETL (extract
Having just spent a frustrating amount of time configuring an automated build with psake
Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems
I am having trouble getting the JSF annotations to work. I have spent some
Having used storyboards for a while now I have found them extremely useful however,
Having spent some time migrating old data into a new drupal site, my first
I've spent so much time trying to figure this out. I'm building a dialog

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.