Not Equal to Each Other?

Stephen Thorne stephen.thorne at gmail.com
Fri Nov 4 03:00:32 CET 2005


On 3 Nov 2005 17:01:08 -0800, ale.of.ginger at gmail.com
<ale.of.ginger at gmail.com> wrote:
> the above so that all the data in one row is not equal to each other,
> is there something I can write to make it simpler?  For example,
> (cellboard[0] is not cellboard[1] is not ... cellboard[8]) only worked
> for the numbers to the left and right of the cell - is there anyway I
> can expand this to cover all numbers in a set range?

Python has an operator call 'in', which will allow you to do what you're after.

"1 in (1,2,3)" will be true
"4 in (1,2,3)" will be false
"not 1 in (1,2,3)" will be false

So you'd be after something along the lines of:
not cellboard[0] in (cellboard[1], ...., celboard[8]).

This seems quite tedious to write, maybe you should consider something
along the lines of using slicing:

not celboard[0] in cellboard[1:8]

I hope i have given you enough tools to do what you're trying to do.

--
Stephen Thorne
Development Engineer



More information about the Python-list mailing list