It's a function to split the coordinates to some small blocks. For example, some country has a coordinates of north-east and south-west, two diagonals. If I set the interval to 0.05, it will returns all the coordinates with interval of 0.05(or some value very close) Note: you could regard the blocks as square, and the length of it's edge is 'interval' So for these function, how to simpfy it and make it more readable ? **sample results** [{'ne_lng': -53.0, 'sw_lat': 71.97411764705882, 'interval': 0.05, 'sw_lng': -53.04941176470588, 'ne_lat': 72.0}, {'ne_lng': -53.0, 'sw_lat': 71.94823529411764, 'interval': 0.05, 'sw_lng': -53.04941176470588, 'ne_lat': 71.97411764705882}] Country = { 'ne_lat' : 89.000000, 'ne_lng' : 179.000000, 'sw_lat' : -89.000000, 'sw_lng' : -179.000000 } def getCoordinate(Country, interval): ne_lng = Country['ne_lng'] ne_lat = Country['ne_lat'] sw_lng = Country['sw_lng'] sw_lat = Country['sw_lat'] interval = float(interval) i = 0 temp = ne_lng lngList = [] n = int((ne_lng - sw_lng)/interval)+1 for _ in range(n): i += 1 lngList.append(temp) temp -= (ne_lng - sw_lng) / n i = 0 temp = ne_lat latList = [] n = int((ne_lng - sw_lng)/interval)+1 for _ in range(n): i += 1 latList.append(temp) temp -= (ne_lat - sw_lat) / n coordinate = [] for ki, vi in enumerate(lngList): for kj, vj in enumerate(latList): if ki == n-1 or kj == n-1: pass else: coordinate.append([vi, vj, lngList[ki+1], latList[kj+1]]) newList = [] for host in coordinate: newDict = { 'ne_lng': host[0], 'ne_lat': host[1], 'sw_lng': host[2], 'sw_lat': host[3], "interval": interval } # print posts.insert(newDict) newList.append(newDict) return newList