Parshant Sharma
Parshant Sharma

Reputation: 11

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)

Upvotes: 1

Views: 488

Answers (2)

quamrana
quamrana

Reputation: 39354

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

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

Upvotes: 1

mrw
mrw

Reputation: 152

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

Upvotes: 0

Related Questions