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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:41:52+00:00 2026-05-30T03:41:52+00:00

probably basic, but couldn’t find it in any other question. I tried: print [.join(seq)

  • 0

probably basic, but couldn’t find it in any other question.
I tried:

print ["".join(seq) for seq in itertools.permutations("00011")]

but got lots of duplications, seems like itertools doesn’t understand all zeroes and all ones are the same…

what am I missing?

EDIT:

oops. Thanks to Gareth I’ve found out this question is a dup of: permutations with unique values.
Not closing it as I think my phrasing of the question is clearer.

  • 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-30T03:41:53+00:00Added an answer on May 30, 2026 at 3:41 am
    list(itertools.combinations(range(5), 2))
    

    returns a list of 10 positions where the two ones can be within the five-digits (others are zero):

    [(0, 1),
     (0, 2),
     (0, 3),
     (0, 4),
     (1, 2),
     (1, 3),
     (1, 4),
     (2, 3),
     (2, 4),
     (3, 4)]
    

    For your case with 2 ones and 13 zeros, use this:

    list(itertools.combinations(range(5), 2))
    

    which returns a list of 105 positions. And it is much faster than your original solution.

    Now the function:

    def combiner(zeros=3, ones=2):
        for indices in itertools.combinations(range(zeros+ones), ones):
            item = ['0'] * (zeros+ones)
            for index in indices:
                item[index] = '1'
            yield ''.join(item)
    
    print list(combiner(3, 2))
    
    ['11000',
     '01100',
     '01010',
     '01001',
     '00101',
     '00110',
     '10001',
     '10010',
     '00011',
     '10100']
    

    and this needs 14.4µs.

    list(combiner(13, 2))
    

    returning 105 elements needs 134µs.

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

Sidebar

Related Questions

This probably is a very very basic question but i can't seem to find
I'm a noob so this is probably basic stuff, but I have tried to
This is probably a pretty basic question, but just something that I wanted to
This is probably a very basic question, but I could not get my way
I have probably worded the question badly, but couldn't figure out how to phrase
I didn't find any dupes of this question, but if there is one or
I realize that this is probably a very basic question, but I have spent
This is probably the MOST basic question and for some reason but I'm a
I know this question is probably very basic, but I am a beginner so
Probably it is a basic question, but could not found the answer anywhere in

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.