OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I take a list of pairs of items (string, tuple) and add (convert) it to a dictionary? [duplicate]

  • Thread starter Thread starter John Fox
  • Start date Start date
J

John Fox

Guest
I'm still a beginner at Python. Here is my list:

Code:
['Kaivopuisto', ('24.950292890004903', '60.155444793742276'),
 'Laivasillankatu', ('24.956347471358754', '60.160959093887129'),
 'Kapteeninpuistikko', ('24.944927399779715', '60.158189199971673'), 
 'Viiskulma', ('24.941775800312996', '60.16098589997938'), 
 'Sepankatu', ('24.93628529982675', '60.157948300373846'), 
 'Hietalahdentori', ('24.929709900391629', '60.162225100108344'), 
 'Designmuseo', ('24.945959999554361', '60.163103199952786'),
 'Vanha kirkkopuisto', ('24.939149900447603', '60.165288299815245'), 
 'Erottajan aukio', ('24.944134928883898', '60.166911666939939')]

I need to create a new dictionary with the string (name) as the key and the tuple as the value. For clarification, the string is the name of a city in Finland and the tuple is longitude and latitude for the city. I really could use some guidance please.

I tried list comprehension, I tried a for loop, I tried the update method - I can't get anything to work.
<p>I'm still a beginner at Python. Here is my list:</p>
<pre><code>['Kaivopuisto', ('24.950292890004903', '60.155444793742276'),
'Laivasillankatu', ('24.956347471358754', '60.160959093887129'),
'Kapteeninpuistikko', ('24.944927399779715', '60.158189199971673'),
'Viiskulma', ('24.941775800312996', '60.16098589997938'),
'Sepankatu', ('24.93628529982675', '60.157948300373846'),
'Hietalahdentori', ('24.929709900391629', '60.162225100108344'),
'Designmuseo', ('24.945959999554361', '60.163103199952786'),
'Vanha kirkkopuisto', ('24.939149900447603', '60.165288299815245'),
'Erottajan aukio', ('24.944134928883898', '60.166911666939939')]
</code></pre>
<p>I need to create a new dictionary with the string (name) as the key and the tuple as the value. For clarification, the string is the name of a city in Finland and the tuple is longitude and latitude for the city. I really could use some guidance please.</p>
<p>I tried list comprehension, I tried a for loop, I tried the update method - I can't get anything to work.</p>
 

Latest posts

Top