Ask Your Question
0

Itertools permutations()

asked 2023-04-17 11:50:54 +0100

Cyrille gravatar image

updated 2023-04-17 11:51:24 +0100

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 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-04-17 15:51:26 +0100

Max Alekseyev gravatar image

updated 2023-04-17 15:52:53 +0100

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

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 ( 2023-04-17 17:06:57 +0100 )edit

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

Max Alekseyev gravatar imageMax Alekseyev ( 2023-04-17 20:35:24 +0100 )edit

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 ( 2023-04-17 23:20:33 +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: 2023-04-17 11:50:54 +0100

Seen: 318 times

Last updated: Apr 17 '23