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.