Python:Dictionnary到web文件列表

Python:Dictionnary到web文件列表,python,web,filelist,Python,Web,Filelist,我有一个文件系统的dict表示,它看起来像这样 { "en": { 'file_name_1': [{meta representation of file_name_1}] or False, {'folder_name': { 'index': [{meta repr. of the index}] or False 'sub_file_1': [{meta repr. of file_name_1}]

我有一个文件系统的dict表示,它看起来像这样

{
    "en": {
        'file_name_1': [{meta representation of file_name_1}] or False,
        {'folder_name': {
            'index': [{meta repr. of the index}] or False
            'sub_file_1': [{meta repr. of file_name_1}] or False,
            }
        }
    }
    "fr": {
        <...>
    }
    'tree_root': path to the tree's parent node
}
我很难弄清楚如何将下一个子树嵌套到迭代中:按照这种方式,我已经完全断开了下一步与此步骤的连接,因此我最终得到了一个混乱的嵌套文件列表


  • 我的一部分问题是口授书没有定单

你将如何着手建立该列表?

因此,按照Hans的建议,我从“收藏”模块转向了OrderedDicts

from collections import OrderedDict
然后显式地构建orderedicts,而不是dicts。它们是不可预打印的,因此很难调试,但它们做得很好

谢谢你,汉斯


我最终还是使用了递归来将列表放在正确的位置。

“我的部分问题是dict没有排序”——那么为什么不使用呢?是的,你当然是对的。我不知道这个选择。RTPM,我应该有。阅读Python手册
from collections import OrderedDict