<bdo id='VO7KV'></bdo><ul id='VO7KV'></ul>

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

    1. <small id='VO7KV'></small><noframes id='VO7KV'>

        <legend id='VO7KV'><style id='VO7KV'><dir id='VO7KV'><q id='VO7KV'></q></dir></style></legend>
      1. <tfoot id='VO7KV'></tfoot>

      2. 如何在 python3 中将 OrderedDict 转换为常规字典

        时间:2023-08-04
          <tbody id='vfiJI'></tbody>
          <i id='vfiJI'><tr id='vfiJI'><dt id='vfiJI'><q id='vfiJI'><span id='vfiJI'><b id='vfiJI'><form id='vfiJI'><ins id='vfiJI'></ins><ul id='vfiJI'></ul><sub id='vfiJI'></sub></form><legend id='vfiJI'></legend><bdo id='vfiJI'><pre id='vfiJI'><center id='vfiJI'></center></pre></bdo></b><th id='vfiJI'></th></span></q></dt></tr></i><div id='vfiJI'><tfoot id='vfiJI'></tfoot><dl id='vfiJI'><fieldset id='vfiJI'></fieldset></dl></div>
              <bdo id='vfiJI'></bdo><ul id='vfiJI'></ul>

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

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

                  <tfoot id='vfiJI'></tfoot>
                • 本文介绍了如何在 python3 中将 OrderedDict 转换为常规字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在努力解决以下问题:我想像这样转换 OrderedDict:

                  I am struggling with the following problem: I want to convert an OrderedDict like this:

                  OrderedDict([('method', 'constant'), ('data', '1.225')])
                  

                  到这样的常规字典中:

                  {'method': 'constant', 'data':1.225}
                  

                  因为我必须将它作为字符串存储在数据库中.转换后,顺序不再重要,所以我无论如何都可以保留有序功能.

                  because I have to store it as string in a database. After the conversion the order is not important anymore, so I can spare the ordered feature anyway.

                  感谢任何提示或解决方案,

                  Thanks for any hint or solutions,

                  推荐答案

                  >>> from collections import OrderedDict
                  >>> OrderedDict([('method', 'constant'), ('data', '1.225')])
                  OrderedDict([('method', 'constant'), ('data', '1.225')])
                  >>> dict(OrderedDict([('method', 'constant'), ('data', '1.225')]))
                  {'data': '1.225', 'method': 'constant'}
                  >>>
                  

                  但是,要将其存储在数据库中,最好将其转换为 JSON 或 Pickle 等格式.使用 Pickle,您甚至可以保持订单!

                  However, to store it in a database it'd be much better to convert it to a format such as JSON or Pickle. With Pickle you even preserve the order!

                  这篇关于如何在 python3 中将 OrderedDict 转换为常规字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 Python 在连接字符串时不进行类型转换? 下一篇:pandas 数据框将列类型转换为字符串或分类

                  相关文章

                  最新文章

                    <bdo id='J6SyI'></bdo><ul id='J6SyI'></ul>

                • <small id='J6SyI'></small><noframes id='J6SyI'>

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