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

Convert [key1,val1,key2,val2] to a dict?

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Guest
Let's say I have a list a in Python whose entries conveniently map to a dictionary. Each even element represents the key to the dictionary, and the following odd element is the value

for example,

Code:
a = ['hello','world','1','2']

and I'd like to convert it to a dictionary b, where

Code:
b['hello'] = 'world'
b['1'] = '2'

What is the syntactically cleanest way to accomplish this?
<p>Let's say I have a list <code>a</code> in Python whose entries conveniently map to a dictionary. Each even element represents the key to the dictionary, and the following odd element is the value</p>

<p>for example,</p>

<pre><code>a = ['hello','world','1','2']
</code></pre>

<p>and I'd like to convert it to a dictionary <code>b</code>, where </p>

<pre><code>b['hello'] = 'world'
b['1'] = '2'
</code></pre>

<p>What is the syntactically cleanest way to accomplish this?</p>
 

Latest posts

H
Replies
0
Views
1
hohohohoho
H
Top