First time here? Check out the FAQ!

Ask Your Question
0

Itertools permutations()

asked 1 year ago

Cyrille gravatar image

updated 1 year ago

I know it should be a Python question, but as there is a way to call itertools in Sagemath I ask the question here. According to the documentation

import itertools as it
l1=[1,2,3]
l2=list(it.permutations(l1,2))
l2

should work. But in fact it returns an error. To the opposit

import itertools as it
l1=[1,2,3]
l2=list(it.permutations(l1))
l2

works correctly. Is it a know problem ?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

First off, you don't need itertools here since similar functionality is provides by Sage - try:

list( Permutations(l1,2) )

If you insist on using itertools.permutations, it wants the second argument be of standard int type (not Sage's sage.rings.integer.Integer') - this should the job:

list( itertools.permutations(l1,int(2)) )
Preview: (hide)
link

Comments

I do not need this particular itertools command but I was intrigued to know how to work with. Now there is a problem. Why am I obliged to use int(2) here and not with other command of the same type ?

Cyrille gravatar imageCyrille ( 1 year ago )

I do not know why, but this is what the error produced by itertools tells us about.

Max Alekseyev gravatar imageMax Alekseyev ( 1 year ago )

Sage has its own class of integers. Some Python tools will gracefully accept Sage integers as input, but not all of them.

John Palmieri gravatar imageJohn Palmieri ( 1 year 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: 1 year ago

Seen: 365 times

Last updated: Apr 17 '23