如何在python中对嵌套字典进行排序?
我的项目中有一个嵌套字典:如何在python中对嵌套字典进行排序?,python,algorithm,list,sorting,dictionary,Python,Algorithm,List,Sorting,Dictionary,我的项目中有一个嵌套字典: >>> dict = { "content": """<p>It is common for content in Arabic, Hebrew, and other languages that use right-to-left scripts to include numerals or include text from other scripts. Both of these typically flow left-
>>> dict = {
"content": """<p>It is common for content in Arabic, Hebrew, and other languages that use right-to-left scripts to include numerals or include text from other scripts. Both of these typically flow left-to-right within the overall right-to-left context. </p>""",
"name": "directory",
"decendent": [
{
"content": """<p>This article tells you how to write HTML where text with different writing directions is mixed <em>within a paragraph or other HTML block</em> (ie. <dfn id="term_inline">inline or phrasal</dfn> content). (A companion article <a href="/International/questions/qa-html-dir"><cite>Structural markup and right-to-left text in HTML</cite></a> tells you how to use HTML markup for elements such as <code class="kw">html</code>, and structural markup such as <code class="kw">p</code> or <code class="kw">div</code> and forms.)</p>""",
"name": "subdirectory",
"decendent": None
},
{
"content": """It tells you how to use HTML markup for elements such as <code class="kw">html</code>, and structural markup such as <code class="kw">p</code> or <code class="kw">div</code> and forms.)""",
"name": "subdirectory_two",
"decendent": [
{
"content": "Name 4",
"name": "subsubdirectory",
"decendent": None
}
]
}
]
}
问题是它返回一组无序的字典作为子代:
在我的例子中,当它们嵌套时,如何对它们进行排序?您的
子代
值只是一个列表。可以对列表进行排序,无论它们引用到哪里。在这里,它在字典里并不重要
您的
子代
列表顺序由os.listdir()
返回的任何顺序设置。您可以对其进行排序,也可以对子对象本身进行排序。例如,使用排序条件进行排序,或使用任何其他条件进行排序
使用os.listdir()
结果上的natural\u sort()
函数,例如:
for entry in natural_sort(os.listdir(dirpath)):
将按排序顺序列出目录条目,以便插入到子代列表中。您的子代值只是一个列表。可以对列表进行排序,无论它们引用到哪里。在这里,它在字典里并不重要
您的子代
列表顺序由os.listdir()
返回的任何顺序设置。您可以对其进行排序,也可以对子对象本身进行排序。例如,使用排序条件进行排序,或使用任何其他条件进行排序
使用os.listdir()
结果上的natural\u sort()
函数,例如:
for entry in natural_sort(os.listdir(dirpath)):
将按排序顺序列出目录条目,以便插入到子代列表中。您的子代值只是一个列表。可以对列表进行排序,无论它们引用到哪里。在这里,它在字典里并不重要
您的子代
列表顺序由os.listdir()
返回的任何顺序设置。您可以对其进行排序,也可以对子对象本身进行排序。例如,使用排序条件进行排序,或使用任何其他条件进行排序
使用os.listdir()
结果上的natural\u sort()
函数,例如:
for entry in natural_sort(os.listdir(dirpath)):
将按排序顺序列出目录条目,以便插入到子代列表中。您的子代值只是一个列表。可以对列表进行排序,无论它们引用到哪里。在这里,它在字典里并不重要
您的子代
列表顺序由os.listdir()
返回的任何顺序设置。您可以对其进行排序,也可以对子对象本身进行排序。例如,使用排序条件进行排序,或使用任何其他条件进行排序
使用os.listdir()
结果上的natural\u sort()
函数,例如:
for entry in natural_sort(os.listdir(dirpath)):
将按排序顺序列出目录条目,以便插入到子体
列表中。您有一个有序的词典列表(不是无序的集合
,完全不同)。列表可以排序,所以只需对列表进行排序。您有一个有序的词典列表(而不是无序的集合
,完全不同)。列表可以排序,所以只需对列表进行排序。您有一个有序的词典列表(而不是无序的集合
,完全不同)。列表可以排序,所以只需对列表进行排序。您有一个有序的词典列表(而不是无序的集合
,完全不同)。列表可以排序,所以只需对列表排序即可。