Ask Your Question

Itertools permutations()

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

Cyrille gravatar image

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

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

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

import itertools as it

works correctly. Is it a know problem ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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

Max Alekseyev gravatar image

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

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


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 +0200 )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 +0200 )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 +0200 )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


Asked: 2023-04-17 11:50:54 +0200

Seen: 220 times

Last updated: Apr 17 '23