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.Sun, 14 Feb 2021 05:39:30 +0100Is there a command like '≠'?https://ask.sagemath.org/question/55677/is-there-a-command-like/ I have the following:
P= Permutations(3)
for i in (1 .. 3):
for u in (1 .. 3):
for j in (1 .. 3):
for v in (1 .. 3):
if i < j or i > j:
if u < v or u > v:
p[i,j, u,v] = [1 if P[m][i-1] == u and P[m][j-1] == v else 0 for m in (0 .. 5)]
I was wondering if I some way I can exchange the lines ' if i < j or i > j' and 'if u < v or u > v' for some command that says 'if i ≠ j' and 'if u ≠ v'.
Fri, 12 Feb 2021 03:14:13 +0100https://ask.sagemath.org/question/55677/is-there-a-command-like/Comment by Sébastien for <p>I have the following:</p>
<pre><code>P= Permutations(3)
for i in (1 .. 3):
for u in (1 .. 3):
for j in (1 .. 3):
for v in (1 .. 3):
if i < j or i > j:
if u < v or u > v:
p[i,j, u,v] = [1 if P[m][i-1] == u and P[m][j-1] == v else 0 for m in (0 .. 5)]
</code></pre>
<p>I was wondering if I some way I can exchange the lines ' if i < j or i > j' and 'if u < v or u > v' for some command that says 'if i ≠ j' and 'if u ≠ v'.</p>
https://ask.sagemath.org/question/55677/is-there-a-command-like/?comment=55686#post-id-55686you may want to do:
import itertools
for (i,u,j,v) in itertools.product((1 .. 3), repeat=4):
...
to avoid such big indentationsSat, 13 Feb 2021 08:59:42 +0100https://ask.sagemath.org/question/55677/is-there-a-command-like/?comment=55686#post-id-55686Answer by cav_rt for <p>I have the following:</p>
<pre><code>P= Permutations(3)
for i in (1 .. 3):
for u in (1 .. 3):
for j in (1 .. 3):
for v in (1 .. 3):
if i < j or i > j:
if u < v or u > v:
p[i,j, u,v] = [1 if P[m][i-1] == u and P[m][j-1] == v else 0 for m in (0 .. 5)]
</code></pre>
<p>I was wondering if I some way I can exchange the lines ' if i < j or i > j' and 'if u < v or u > v' for some command that says 'if i ≠ j' and 'if u ≠ v'.</p>
https://ask.sagemath.org/question/55677/is-there-a-command-like/?answer=55678#post-id-55678The python operator you are looking for is `!=`.
x = 5
y = 3
x != y
returns `True`.Fri, 12 Feb 2021 03:25:20 +0100https://ask.sagemath.org/question/55677/is-there-a-command-like/?answer=55678#post-id-55678Comment by slelievre for <p>The python operator you are looking for is <code>!=</code>.</p>
<pre><code>x = 5
y = 3
x != y
</code></pre>
<p>returns <code>True</code>.</p>
https://ask.sagemath.org/question/55677/is-there-a-command-like/?comment=55683#post-id-55683Well... In fact, `x != y` would return `True` but strictly speaking `print(x != y)` prints `True` without returning anything. More directly, `3 != 5` returns `True`.Sat, 13 Feb 2021 01:15:51 +0100https://ask.sagemath.org/question/55677/is-there-a-command-like/?comment=55683#post-id-55683Comment by cav_rt for <p>The python operator you are looking for is <code>!=</code>.</p>
<pre><code>x = 5
y = 3
x != y
</code></pre>
<p>returns <code>True</code>.</p>
https://ask.sagemath.org/question/55677/is-there-a-command-like/?comment=55701#post-id-55701You are right, thanks!Sun, 14 Feb 2021 05:39:30 +0100https://ask.sagemath.org/question/55677/is-there-a-command-like/?comment=55701#post-id-55701