<small id='rVpwr'></small><noframes id='rVpwr'>

  • <legend id='rVpwr'><style id='rVpwr'><dir id='rVpwr'><q id='rVpwr'></q></dir></style></legend>

      <tfoot id='rVpwr'></tfoot>

        <bdo id='rVpwr'></bdo><ul id='rVpwr'></ul>
      <i id='rVpwr'><tr id='rVpwr'><dt id='rVpwr'><q id='rVpwr'><span id='rVpwr'><b id='rVpwr'><form id='rVpwr'><ins id='rVpwr'></ins><ul id='rVpwr'></ul><sub id='rVpwr'></sub></form><legend id='rVpwr'></legend><bdo id='rVpwr'><pre id='rVpwr'><center id='rVpwr'></center></pre></bdo></b><th id='rVpwr'></th></span></q></dt></tr></i><div id='rVpwr'><tfoot id='rVpwr'></tfoot><dl id='rVpwr'><fieldset id='rVpwr'></fieldset></dl></div>
      1. 是否可以将列表转换为嵌套的键字典*无需*递归?

        Is it possible to turn a list into a nested dict of keys *without* recursion?(是否可以将列表转换为嵌套的键字典*无需*递归?)

      2. <tfoot id='E5AVW'></tfoot>
        <legend id='E5AVW'><style id='E5AVW'><dir id='E5AVW'><q id='E5AVW'></q></dir></style></legend>

          <small id='E5AVW'></small><noframes id='E5AVW'>

          1. <i id='E5AVW'><tr id='E5AVW'><dt id='E5AVW'><q id='E5AVW'><span id='E5AVW'><b id='E5AVW'><form id='E5AVW'><ins id='E5AVW'></ins><ul id='E5AVW'></ul><sub id='E5AVW'></sub></form><legend id='E5AVW'></legend><bdo id='E5AVW'><pre id='E5AVW'><center id='E5AVW'></center></pre></bdo></b><th id='E5AVW'></th></span></q></dt></tr></i><div id='E5AVW'><tfoot id='E5AVW'></tfoot><dl id='E5AVW'><fieldset id='E5AVW'></fieldset></dl></div>

                <bdo id='E5AVW'></bdo><ul id='E5AVW'></ul>
                  <tbody id='E5AVW'></tbody>

                • 本文介绍了是否可以将列表转换为嵌套的键字典*无需*递归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个如下列表:

                  Supposing I had a list as follows:

                  mylist = ['a','b','c','d']
                  

                  是否可以从这个列表中不使用使用递归/递归函数创建以下字典?

                  Is it possible to create, from this list, the following dict without using recursion/a recursive function?

                  {
                    'a': {
                      'b': {
                        'c': {
                          'd': { }
                        }
                      }
                    }
                  }
                  

                  推荐答案

                  对于简单的情况,简单的迭代和构建,从头到尾都可以:

                  For the simple case, simply iterate and build, either from the end or the start:

                  result = {}
                  for name in reversed(mylist):
                      result = {name: result}
                  

                  result = current = {}
                  for name in mylist:
                      current[name] = {}
                      current = current[name]
                  

                  第一个解决方案也可以使用 reduce():

                  The first solution can also be expressed as a one-liner using reduce():

                  reduce(lambda res, name: {name: res}, reversed(mylist), {})
                  

                  这篇关于是否可以将列表转换为嵌套的键字典*无需*递归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)

                • <tfoot id='ArXTj'></tfoot>
                  • <legend id='ArXTj'><style id='ArXTj'><dir id='ArXTj'><q id='ArXTj'></q></dir></style></legend>
                      <i id='ArXTj'><tr id='ArXTj'><dt id='ArXTj'><q id='ArXTj'><span id='ArXTj'><b id='ArXTj'><form id='ArXTj'><ins id='ArXTj'></ins><ul id='ArXTj'></ul><sub id='ArXTj'></sub></form><legend id='ArXTj'></legend><bdo id='ArXTj'><pre id='ArXTj'><center id='ArXTj'></center></pre></bdo></b><th id='ArXTj'></th></span></q></dt></tr></i><div id='ArXTj'><tfoot id='ArXTj'></tfoot><dl id='ArXTj'><fieldset id='ArXTj'></fieldset></dl></div>
                      • <bdo id='ArXTj'></bdo><ul id='ArXTj'></ul>

                        <small id='ArXTj'></small><noframes id='ArXTj'>

                            <tbody id='ArXTj'></tbody>