[Python] convert string which contains sub string to dictionary

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am tring to convert particular strings which are in particular format to Python dictionary. String format is like below,

    st1 = 'key1 key2=value2 key3="key3.1, key3.2=value3.2 , key3.3 = value3.3, key3.4" key4'


    I want to parse it and convert to dictionary as below,

    dict1 {
    key1: None,
    key2: value2,
    key3: {
    key3.1: None,
    key3.2: value3.2,
    key3.3: value3.3,
    key3.2: None
    }
    key4: None,



    I tried to use python re package and string split function. not able to acheive the result. I have thousands of string in same format, I am trying to automate it. could someone help.

    Continue reading...

Compartilhe esta Página