I want to search for positions inside a range of integers. How to improve the code in terms of efficiency, since both my search list and the ranges are very big:
#Range list with ids
range_lst = [(121000, 122000, 'foo'), (123456, 124557, 'bar'), (156789, 163659, 'egg')]
# Positions which we want to scan
pos = [123456, 369369]
# Neighbouring windows size
window_size = 10000
for p in pos:
for r in range_lst:
range_area = range(r[0], r[1])
range_area_window = range(r[0]-window_size, r[1]+window_size)
id = r[2]
if p in range_area:
print (p, id, 'exact hit!')
else:
# If we don't find an exact hit, we check the neighbouring region +- 10000
if p in range_area_window:
print (p, id, 'neighbour hit!')