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

Discussão em 'Python' iniciado por Stack, Novembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    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,

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


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

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


    What is the syntactically cleanest way to accomplish this?

    Continue reading...

Compartilhe esta Página