Ask Your Question
1

permutation with repetition count

asked 2019-01-01 06:45:36 -0500

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]

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-01-02 16:18:26 -0500

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)]
edit flag offensive delete link more

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 ( 2019-01-06 00:06:21 -0500 )edit

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

Senthil gravatar imageSenthil ( 2019-01-06 00:22:00 -0500 )edit

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: 2019-01-01 06:28:57 -0500

Seen: 45 times

Last updated: Jan 02