change list of tuples to 2 lists - Python
<p>I have a list of tuples (in this case its coordinates for latitude and longitude)</p>

<pre><code>[(51.69768233153901, -5.039923897568534),
(52.14847612092221, 0.33689512047881015),
(52.14847612092221, 0.33689512047881015),
....]
</code></pre>

<p>I am trying to get them into 2 separate lists (one for latitude and one for longitude)</p>

<p>I cannot work out how to loop through to add them to the lists, so far I have: </p>

<pre><code>lat = latlon_df.at[0,'LatLon'][0] 
lon = latlon_df.at[0,'LatLon'][1]
</code></pre>

<p>which identifies the first of each. Could someone show me how do create the 2 new lists?</p>

<p>Thanks for your help!</p>

<p>Try this:</p>

<pre><code>coords = [(51.69768233153901, -5.039923897568534),
          (52.14847612092221, 0.33689512047881015),
          (52.14847612092221, 0.33689512047881015)]

lat, lon = map(list, zip(*coords))
</code></pre>

<p>Adapted from this answer here <a href="http://stackoverflow.com/questions/19339/a-transpose-unzip-function-in-python-inverse-of-zip">A Transpose/Unzip Function in Python (inverse of zip)</a></p>

python tuples ipython