you can use the bisect module to avoid these if statements. Here is a quick and dirty example.
from functools import total_ordering import bisect @total_ordering class Point: def __init__(self, X, Y): self.X = X self.Y = Y def __eq__(self, other): return self.X == other.X and self.Y == other.Y def __lt__(self, other): return self.X < other.X and self.Y < other.Y print [(float(x)/2, float(x)/2) for x in xrange(0, 23)]
(0.5, 0.5), (1.0, 1.0), (1.5, 1.5), (2.0, 2.0), (2.5, 2.5), (3.0, 3.0), (3.5, 3.5)), (4.0, 4.0), (4.5, 4.5), (5.0, 5.0) , (5.5, 5.5), (6.0, 6.0), (6.5, 6.5), (7.0, 7.0) (10.0, 10.0), (10.5, 10.0), (11.0, 11.0)
points = [Point(float(x)/2, float(x)/2) for x in xrange(0, 23)] types = [chr(x) for x in xrange(65, 91)] print types
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L' ', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', '' Y ',' Z ']
print types[bisect.bisect(points, Point(0.1, 0.1)) - 1]
A
print types[bisect.bisect(points, Point(0.6, 0.6)) - 1]
IN