我有这本字典:
statuses = {
'pending' : {'status_for':'all', 'position':1},
'cancelled' : {'status_for':'all','position':2},
'approved' : {'status_for':'owner', 'position':1},
'rejected - owner' : {'status_for':'owner', 'position':2},
'accepted' : {'status_for':'dev', 'position':1},
'rejected - developer' : {'status_for':'dev', 'position':3},
'closed' : {'status_for':'dev', 'position':5},
}
我还有一个函数可以提取任何一个或看起来像这样status_for
的所有值并将其放入 PyQt QComboBox:owner
dev
for s in statuses:
if statuses[s]['status_for'] == "dev" or statuses[s]['status_for'] == "all":
cb_developer_status.addItem(s.capitalize(), s)
不过,我想按position
价值订购这些。有什么好的方法可以做到这一点,以便当我按组合框填充时,我会按照预定义的顺序进行填充?
我意识到上面的代码片段正在检查“dev”和“all”,我现在的假设是我必须遍历字典两次才能按照我希望的顺序获取两个单独的块(即。'all ' 出现在 'dev' 之前)。
我看到了这篇文章,但我不确定如何将此答案转换为字典词典。