1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How do I convert a list of dicts to a dict?

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    How can I convert a list of dicts to a dict? Below is the list of dicts:

    data = [{'name': 'John Doe', 'age': 37, 'sex': 'M'},
    {'name': 'Lisa Simpson', 'age': 17, 'sex': 'F'},
    {'name': 'Bill Clinton', 'age': 57, 'sex': 'M'}]


    I want to convert this to:

    data = {'John Doe': {'name': 'John Doe', 'age': 37, 'sex': 'M'},
    'Lisa Simpson': {'name': 'Lisa Simpson', 'age': 17, 'sex': 'F'},
    'Bill Clinton': {'name': 'Bill Clinton', 'age': 57, 'sex': 'M'}}

    Continue reading...

Compartilhe esta Página