简体   繁体   English

分隔字典中的逗号分隔值以分隔字符串列表

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

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

Output: {'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(','))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在列表中分隔逗号分隔值以使其成为列表的单个值 - How to separate comma separated values in a list to make it individual values of a list 熊猫-如何用逗号分隔的字符串分隔和分组 - Pandas - How to separate and group by comma separated strings 包含可变长度和逗号分隔的值字符串的熊猫行列如何堆叠成单独的值? - How is a pandas column of rows containing variable length and comma separated strings of values, stacked into separate values? 在 Python 中用逗号分隔列表中的值 - Separate values in a list by comma in Python 将逗号分隔值的字符串列表写入CSV - Writing a list of strings of comma separated values into a CSV 如何分隔逗号分隔的列表 - How to separate comma separated lists 在列表或字符串中获取字典值的更好方法。 每个值都是一个字符串,由多个用逗号分隔的字符串组成 - Better way to get dictionary values in a list or a sting. Each value is a string consisting of multiple strings separated by a comma 拆分逗号分隔的值并存储在python 3.x中的单独行中? - spliting comma separated values and storing in separate row in python 3.x? 在Django模板中将列表转换为逗号分隔的值 - Convert list to comma separate values in django template Python逗号分隔列表 - Python Comma Separate List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM