Ask Your Question
0

Is there a command like '≠'?

asked 2021-02-12 03:14:13 +0100

phcosta gravatar image

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'.

edit retag flag offensive close merge delete

Comments

1

you may want to do:

import itertools
for (i,u,j,v) in itertools.product((1 .. 3), repeat=4):
    ...

to avoid such big indentations

Sébastien gravatar imageSébastien ( 2021-02-13 08:59:42 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2021-02-12 03:25:20 +0100

cav_rt gravatar image

updated 2021-02-14 05:37:14 +0100

The python operator you are looking for is !=.

x = 5
y = 3
x != y

returns True.

edit flag offensive delete link more

Comments

Well... In fact, x != y would return True but strictly speaking print(x != y) prints True without returning anything. More directly, 3 != 5 returns True.

slelievre gravatar imageslelievre ( 2021-02-13 01:15:51 +0100 )edit

You are right, thanks!

cav_rt gravatar imagecav_rt ( 2021-02-14 05:39:30 +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: 2021-02-12 03:14:13 +0100

Seen: 275 times

Last updated: Feb 14 '21