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

Time:10-05

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)

CodePudding user response:

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

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

CodePudding user response:

for key in input:
    input[key] = list(input[key].split(','))
  • Related