ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 17 Apr 2023 23:20:33 +0200Itertools permutations()https://ask.sagemath.org/question/67656/itertools-permutations/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 ?Mon, 17 Apr 2023 11:50:54 +0200https://ask.sagemath.org/question/67656/itertools-permutations/Answer by Max Alekseyev for <p>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</p>
<pre><code>import itertools as it
l1=[1,2,3]
l2=list(it.permutations(l1,2))
l2
</code></pre>
<p>should work. But in fact it returns an error. To the opposit </p>
<pre><code>import itertools as it
l1=[1,2,3]
l2=list(it.permutations(l1))
l2
</code></pre>
<p>works correctly. Is it a know problem ?</p>
https://ask.sagemath.org/question/67656/itertools-permutations/?answer=67657#post-id-67657First 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)) )Mon, 17 Apr 2023 15:51:26 +0200https://ask.sagemath.org/question/67656/itertools-permutations/?answer=67657#post-id-67657Comment by John Palmieri for <p>First off, you don't need <code>itertools</code> here since similar functionality is provides by Sage - try:</p>
<pre><code>list( Permutations(l1,2) )
</code></pre>
<p>If you insist on using <code>itertools.permutations</code>, it wants the second argument be of standard <code>int</code> type (not Sage's <code>sage.rings.integer.Integer'</code>) - this should the job:</p>
<pre><code>list( itertools.permutations(l1,int(2)) )
</code></pre>
https://ask.sagemath.org/question/67656/itertools-permutations/?comment=67669#post-id-67669Sage has its own class of integers. Some Python tools will gracefully accept Sage integers as input, but not all of them.Mon, 17 Apr 2023 23:20:33 +0200https://ask.sagemath.org/question/67656/itertools-permutations/?comment=67669#post-id-67669Comment by Max Alekseyev for <p>First off, you don't need <code>itertools</code> here since similar functionality is provides by Sage - try:</p>
<pre><code>list( Permutations(l1,2) )
</code></pre>
<p>If you insist on using <code>itertools.permutations</code>, it wants the second argument be of standard <code>int</code> type (not Sage's <code>sage.rings.integer.Integer'</code>) - this should the job:</p>
<pre><code>list( itertools.permutations(l1,int(2)) )
</code></pre>
https://ask.sagemath.org/question/67656/itertools-permutations/?comment=67662#post-id-67662I do not know why, but this is what the error produced by `itertools` tells us about.Mon, 17 Apr 2023 20:35:24 +0200https://ask.sagemath.org/question/67656/itertools-permutations/?comment=67662#post-id-67662Comment by Cyrille for <p>First off, you don't need <code>itertools</code> here since similar functionality is provides by Sage - try:</p>
<pre><code>list( Permutations(l1,2) )
</code></pre>
<p>If you insist on using <code>itertools.permutations</code>, it wants the second argument be of standard <code>int</code> type (not Sage's <code>sage.rings.integer.Integer'</code>) - this should the job:</p>
<pre><code>list( itertools.permutations(l1,int(2)) )
</code></pre>
https://ask.sagemath.org/question/67656/itertools-permutations/?comment=67661#post-id-67661I 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 ?Mon, 17 Apr 2023 17:06:57 +0200https://ask.sagemath.org/question/67656/itertools-permutations/?comment=67661#post-id-67661