Ask Your Question
1

permutation with repetition count

asked 2019-01-01 13:45:36 +0100

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 23:18:26 +0100

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 07:06:21 +0100 )edit

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

Senthil gravatar imageSenthil ( 2019-01-06 07:22:00 +0100 )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 13:28:57 +0100

Seen: 1,132 times

Last updated: Jan 02 '19