Ask Your Question
1

permutation with repetition count

asked 6 years ago

Senthil gravatar image

How to achieve below permutation ?

Permutation set = [0,1,2]

Permutation sub set cardinality = 2; ( example : [0,0] , [1,2] ....)

Repetition = true;

Result : [0,0] [0,1] [0,2] [1,0] [1,1] [1,2] [2,0] [2,1] [2,2]

How to generalize for the Permutation set = [0,1,2,3...n-1]

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 6 years ago

tmonteil gravatar image

You can use product provided by the itertools Python module:

sage: list(product([0,1,2], repeat=2))
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
Preview: (hide)
link

Comments

Thanks a lot. It is working.

My list size is very huge.. Is there anyway to do via Iteration instead of filling list initially itself?

So that I can use iteration.next .

Thanks in advance

Senthil gravatar imageSenthil ( 6 years ago )

I am new to Python and sage. I have removed list now it is converted to Iterate

Senthil gravatar imageSenthil ( 6 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 1,286 times

Last updated: Jan 02 '19