比方说,我与这段文字age_gender.txt
将字典的值转换为列表?
Female:18,36,35,49,19
Male:23,22,26,26,26
这里给出的是我到目前为止的代码
file = open("age_gender.txt")
contents = file.read().splitlines()
new_dictionary = dict(item.split(":") for item in contents)
return new_dictionary
当我调用该函数readfile()
这是输出我得到的价值不过名单仍然在引号中。你如何将每个值转换为列表?
{'Female': '18,36,35,49,19', 'Male': '23,22,26,26,26'}
我想达到的输出是这样的
{'Female': [18,36,35,49,19], 'Male': [23,22,26,26,26]}
请修复缩进 – flaschbier