我知道这是问早些时候,但我试图,但无法帮助。你知道吗
我有下面的字典,想转换成列表,转换成列表的最好方法是什么
dct = {'result': ['activeaddresses', 'exchangevolume(usd)', 'marketcap(usd)', 'mediantxvalue(usd)', 'price(usd)', 'txcount', 'txvolume(usd)']}
dList = list(dct.values())
结果:
[['activeaddresses', 'exchangevolume(usd)', 'marketcap(usd)', 'mediantxvalue(usd)', 'price(usd)', 'txcount', 'txvolume(usd)']]
我需要拆分列表:
['activeaddresses', 'exchangevolume(usd)', 'marketcap(usd)', 'mediantxvalue(usd)', 'price(usd)', 'txcount', 'txvolume(usd)']
稍后,我想将“dList”中的项目列表与另一个列表进行比较。你知道吗
如果知道列表是与
'result'
键关联的值,只需调用dct['result']
。你知道吗将值转换为列表是不必要的、低效的,如果dict有1个以上(键、值)对,则可能返回错误的值。你知道吗
你的字典只有一个值,它本身就是一个元素列表。所以只要调用
result
键,就可以得到列表值。你知道吗如果您想从代码中得到列表,请添加索引
[0]
,如下所示:dList = list(dct.values())[0]
希望这有帮助!干杯!你知道吗
相关问题 更多 >
编程相关推荐