我有一个如下所示的字典,我想将表示 1、1 的值存储在列表中。
sc_dict=[('n', {'rh': 1}), ('n', {'rhe': 1}), ('nc', {'rhex': 1})]
我想要一个数组[1,1,1]
。
这是我的代码:
dict_part = [sc[1] for sc in sc_dict]
print(dict_part[1])
L1=[year for (title, year) in (sorted(dict_part.items(), key=lambda t: t[0]))]
print(L1)
最佳答案
>>> [v for t1, t2 in sc_dict for k, v in t2.items()]
[1, 1, 1]
t1
和t2
分别是每个元组的第一项和第二项,k
、v
字典 t2
中的键值对。
关于python - 如何从元组列表中的字典中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49861820/