Skip to content

Instantly share code, notes, and snippets.

@angeloped
Created June 5, 2020 18:13
Show Gist options
  • Save angeloped/548dc33bffaa9ff0208410eb459a2cf7 to your computer and use it in GitHub Desktop.
Save angeloped/548dc33bffaa9ff0208410eb459a2cf7 to your computer and use it in GitHub Desktop.
Geolocation Sorting Algorithm
sorted_geo = []
def Geolocation_sorter(geo_info): # arg={COUNTRY:'',LNG:'',LAT:''}
if not bool(sorted_geo): # if empty
sorted_geo.append(geo_info)
return
i = 0
while i < len(sorted_geo):
if (float(geo_info["LNG"]) >= float(sorted_geo[i]["LNG"]) and float(geo_info["LNG"]) <= float(sorted_geo[:i+1][0]["LNG"])):
sorted_geo.insert(i+1, geo_info)
break
elif (float(geo_info["LNG"]) < float(sorted_geo[i]["LNG"])):
sorted_geo.insert(i, geo_info)
break
else:
i += 1
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment