简体   繁体   中英

Separate the comma separated values in a dictionary to separate strings list

Input: {'canada': 'america,usa', 'japan': 'tokio,Africa,Europe}

Output: {'canada': ['america','usa'], 'japan': ['tokio','Africa','Europe']}

Something like this:

Dictionary= dict(e.split(',') for e in input)

You can have a dictionary comprehension to create the new dict.

Dictionary= {k:e.split(',') for k,e in input.items()}
for key in input:
    input[key] = list(input[key].split(','))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM