-1

How to loop multi-variable data like this in python ?
I have latitude and longitude data and I want to pass all these value and run it for 5 times.

e.g.

round 1
lat = 13.29 , longitude = 100.34 city = 'ABC'

round 2
lat = 94.09834 ,longitude = 103.34 city = 'XYZ'

,... ,.. ,round 5

Very new to python world. Thank you for every kind comment and suggestion :)

Paper.J
  • 13
  • 1
  • 5
  • Does this data already exist in your program? What do you mean by "pass all these value and run it for 5 times"? You can make a program with a list containing 5 "lat/long/city" objects, then iterate over the objects and do something with the data. But without more details it's unclear what you'd like to achieve – byxor Jan 14 '22 at 17:32
  • If your five rounds are in a list of dictionaries then this might help: https://stackoverflow.com/questions/35864007/python-3-5-iterate-through-a-list-of-dictionaries – JonSG Jan 14 '22 at 17:40

2 Answers2

0

you can do something like this:

cities = ["Rome", "NYC"]
latitude = [41.2925, 40.730610]
longitude = [12.5736, 73.935242]
for (a, b, c) in zip(longitude, latitude, cities): #zips the lists together
     print ("long = %s, lat= %s, city:%s" % (a, b, c)) 

Output :

long = 12.5736, lat= 41.2925, city:Rome
long = 73.935242, lat= 40.73061, city:NYC
XxJames07-
  • 1,833
  • 1
  • 4
  • 17
0

You should store the data in a proper data structure which will allow you to loop it, I would suggest storing it as a list of dictionaries. It would look something like this

data = [{'city':'city1','lat':'lat1','alt':'alt1'},
{'city':'city2','lat':'lat2','alt':'alt2'}]

The iteration over the data would look as following:

for d in data:
    print(f" lat: {d['lat']}, alt: {d['alt']} , city: {d['city']}")

Alik.Koldobsky
  • 334
  • 1
  • 10