A
A
Anton Sukhanov2014-02-07 13:32:56
Python
Anton Sukhanov, 2014-02-07 13:32:56

How to compare a number in python so that the result is always true/false?

I'm solving an Olympiad problem in programming. Given a set of points. You need to calculate the area of ​​the largest possible quadrilateral.
First, I formed a list of points [(x1,y1), (x2,y2), (xn,yn)] and then worked with them. But then I realized that it is not really needed and you can find the points I need in the first cycle, where I read the initial data. In addition, the maximum number of points can be obtained without using arrays (after consultation, it was decided that a list could be used to store the coordinates of the vertices of the quadrilateral).
I used to do this:

top = points[0]
for point in points:
    if (point[0] == 0) and (point[1] > top[1]): top = [0,point[1]]

Now I want to do this:
top = [*что-то*, *что-то*]
for ... :
    if (point[0] == 0) and (point[1] > top[1]): top = [0,point[1]]

Perhaps there is some beautiful solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sheknitrtch, 2014-02-07
@anton_suhanov

As far as I know in Python 2.x the constant Noneis always less than any number

print None < 1024  #True
print None < 0     #True
print None < -1024 #True

But in Python 3.x, such a comparison is not allowed, and an Exception will be thrown.
See also the question on Stackoverflow

J
JRazor, 2014-02-07
@JRazor

In Python 3, you can compare, for example, like this:

>>> not 1
False
>>> not 0
True

Or explicitly check the object reference:
>>> 1 is None
False

Boolean values:
>>> bool(1)
True
>>> bool(0)
False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question