Python Neighbourhood Algorithm