You have a list of tuples. Swapping tuples is simply a matter of accessing the 1st index in the tuple before 0 index and storing the output.
EL = (42.7358, -84.4844)
Det = (42.3831, -83.1022)
Kal = (42.2747, -85.5883)
AA = (42.2753, -83.7308)
Lan = (42.7092, -84.5539)
GR = (42.9614, -85.6558)
SSM = (46.4844, -84.3656)
cities = [EL, Det, Kal, AA, Lan, GR, SSM]
print(cities)
#Output:
[(42.7358, -84.4844),
(42.3831, -83.1022),
(42.2747, -85.5883),
(42.2753, -83.7308),
(42.7092, -84.5539),
(42.9614, -85.6558),
(46.4844, -84.3656)]
cities2 = [(x[1], x[0]) for x in cities]
print(cities)
#Output:
[(-84.4844, 42.7358),
(-83.1022, 42.3831),
(-85.5883, 42.2747),
(-83.7308, 42.2753),
(-84.5539, 42.7092),
(-85.6558, 42.9614),
(-84.3656, 46.4844)]
As for reversing a list, there are many ways to reverse a list. some create a copy, others modify the original list, such as .reverse()
cities3 = cities[::-1] #created a reversed copy.
#Alternatively
cities3 = list(reversed(cities))
Lastly however, a recommendation.
Your lists of tuples as-is do not make a lot of sense, but the name labels give the tuples meaning.
You should consider a different data structure to store this information,and dictionaries in this case makes sense. You can think of them as mappings between key:value
pairs.
EL = (42.7358, -84.4844)
Det = (42.3831, -83.1022)
Kal = (42.2747, -85.5883)
AA = (42.2753, -83.7308)
Lan = (42.7092, -84.5539)
GR = (42.9614, -85.6558)
SSM = (46.4844, -84.3656)
cities = [EL, Det, Kal, AA, Lan, GR, SSM]
city_names = ["EL", "Det", "Kal", "AA", "Lan", "GR", "SSM"]
cities_dict = dict(zip(city_names, cities))
Note that the above code is equivalent the following:
cities_dict = {"EL": EL,
"Det": Det,
"Kal": Kal,
"AA": AA,
"Lan": Lan,
"GR": GR,
"SSM": SSM
}
print(cities_dict)
#Output:
{'EL': (42.7358, -84.4844),
'Det': (42.3831, -83.1022),
'Kal': (42.2747, -85.5883),
'AA': (42.2753, -83.7308),
'Lan': (42.7092, -84.5539),
'GR': (42.9614, -85.6558),
'SSM': (46.4844, -84.3656)}
Now, a caveat, dictionaries are unordered inherently. If you want a dict-like data structure that supports ordering, use an OrderedDict.
from collections import OrderedDict
cities = [EL, Det, Kal, AA, Lan, GR, SSM]
city_names = ["EL", "Det", "Kal", "AA", "Lan", "GR", "SSM"]
cities_dict = OrderedDict(zip(city_names, cities))
print(cities_dict)
cities2_dict = OrderedDict((key, (v[1], v[0])) for (key,v) in cities_dict.items())
print(cities2_dict)
cities3_dict = OrderedDict(reversed(cities_dict.items()))
print(cities3_dict)