如何在多层python字典中找到最小值,以及它的"路径"(即叶子值的键列表)

Cat*_*Cat 1 python sorting dictionary

我有一个以下格式的python字典:

d = 
{
  'category' :
  {
    'genre': <int_value>
  }
}
Run Code Online (Sandbox Code Playgroud)

我想<int_value>在原始字典中找到最小的,以及它的"路径".

例如,如果

d = 
{
  'free':
  {
    'adventure' : 23,
    'arcade' : 101,
  },
  'paid':
  {
    'arcade' : 130,
  }
}
Run Code Online (Sandbox Code Playgroud)

......结果应该是("free", "adventure", 23).

谁能想到这样的单线程?

提前致谢!

per*_*eal 5

print min((d[c][x], c, x) for c in d for x in d[c])
Run Code Online (Sandbox Code Playgroud)

并重新安排:

print min( (d[c][x], x, c) for c in d for x in d[c] )[::-1]
Run Code Online (Sandbox Code Playgroud)