2

So this is what im trying

list(itertools.combinations_with_replacement('01', 2))

but this is generating [('0', '0'), ('0', '1'), ('1', '1')]

I still need a ('1','0') tuple, is there a way to make itertools also do combinations and order?

1
  • 3
    Rollback to Revision 3, Don't change question, If you have other doubt ask a new question. Commented Feb 13, 2014 at 6:03

1 Answer 1

5

Use itertools.product instead:

>>> import itertools
>>> list(itertools.product('01', repeat=2))
[('0', '0'), ('0', '1'), ('1', '0'), ('1', '1')]
Sign up to request clarification or add additional context in comments.

3 Comments

FYI, you answered this in 48th sec, since the question was posted. :(
@thefourtheye, in 48 secs with typo! Thank you for the correction.
seriously, i got as far as copy/pasting OP's base code by the time you'd posted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.