Decide if 4 lengths form a square, rectangle or neither I have a list of lists of 4 integers, each representing the length of one side of a tetragon in clockwise order (so each number is the length of the side of the right-hand-adjacent-side of the previous one). Integers can be negative or positive or 0. 

My idea is that if any of the sides are less than or equal to 0 then it's not a valid tetragon. Then if the lengths of all the sides are equal then it can form a square. Then if lengths of opposing sides are equal then it can form a rectangle, otherwise it's neither.

tgons=[[1,1,1,1],[1,2,1,2],[1,2,3,4],[-1,-2,-1,-2],[1,0,1,0]]
squares=0
rects = 0
neithers = 0
for gon in tgons:
    if any(n &lt;= 0 for n in gon): #if any integers &lt;= 0, it's invalid
        neithers+=1
    elif len(set(gon)) == 1: #if all integers are equal, it's a square
        squares+=1
    elif gon[0] == gon[2] and gon[1] == gon[3]: #if both pairs of opposing sides have equal length, it's a rectangle
        rects+=1
    else:
        neithers+=1
print squares,rects,neithers


This code apparently fails one out of a few test cases (on a certain website). I've thrown all the test cases I could think of at it and I've not been able to get it to fail so far. Is there really a test case that it fails?
Why do we need a set to find a square?
Why is a square not a subset of rectangle?
You can do the any check in the gon[0] == gon[2].
Why no filter on length of gon? Pentagons aren't squares...
gon is a poor name... do you mean polygon?
I agree with holroy, -5 makes sense, but 0 does not.


So I would do:

for shape in tgons:
    if shape[0] == shape[2] &gt; 0 and shape[1] == shape[3] &gt; 0 and len(shape) == 4:
        if shape[0] == shape[1]:
            squares += 1
        else:
            rects += 1
    else:
        neithers += 1


This can also be changed to allow all 2D rects/squares. (not lines.)

if shape[0] == shape[2] != 0 and shape[1] == shape[3] != 0 and len(shape) == 4:




Also follow PEP8 a bit more, as then you'll have easier to read code.
You mostly need more spaces:


Before and after infix operators.
After but not before commas.