-1

I'm trying to measure distance through geopy.

I have already gotten the latitude and longitude of the location with geopy but it's saved as individual variables. ie.

  getloc = loc.geocode(a)
  loclat = getloc.latitude
  loclon = getloc.longitude

I am trying to combine these two variables into a single variable and add it to a list so each location has their latitude and longitude as I add each location lat/lon into a new list. ie. I want list loccoor to print out the latitude and longitude as:

41.49008, -71.312796
41.499498, -81.695391

I have tried append and extend, but it adds to the list each item instead of together. ie

41.49008
-71.312796
41.499498
-81.695391

If i use loccoor.append(loclat + loclon) it adds it together because its integers.

I looked into this and found insert to insert it into a position but how would I insert both values into the same position?

How do I merge these two variables as one?

1 Answers1

0

If it is just for printing, you can append them as a string. Below is an example code.

loccoor =[]
loccoor.append(str(41.49008) + "," + str(-71.312796))
loccoor.append(str(41.499498) + "," + str(-81.695391))

for loc in loccoor:
    #For printing location
    print(loc)
    
    #If you need to retreive the values.
    loclat = float(loc.split(",")[0])
    loclon = float(loc.split(",")[1])

output

41.49008,-71.312796
41.499498,-81.695391
KRG
  • 655
  • 7
  • 18