• <bdo id='KgBv1'></bdo><ul id='KgBv1'></ul>

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

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

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

        在 Python 字典中查找和替换值

        Finding and replacing a value in a Python dictionary(在 Python 字典中查找和替换值)
        <legend id='b70Vv'><style id='b70Vv'><dir id='b70Vv'><q id='b70Vv'></q></dir></style></legend>

        <tfoot id='b70Vv'></tfoot>

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

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

                <tbody id='b70Vv'></tbody>
                • 本文介绍了在 Python 字典中查找和替换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 stackoverflow 的完全新手,所以如果我最终将其发布在错误的地方(或任何其他与新手相关的 mitakes!谢谢!),请原谅我.

                  I'm a complete newbie to stackoverflow, so please excuse me if I end up posting this in the wrong place (or any other newbie-related mitakes! Thanks!).

                  我的问题与 Python 3.x 有关,我试图在其中基本上访问一个非常小的字典中的一个值(3 个键,每个 1 个值).我在网上(和这里)搜索了高和低,但似乎找不到与替换字典中的值有关的任何内容.我找到了替换"功能,但似乎不适用于字典.

                  My question pertains to Python 3.x, where I am trying to basically access a value in a very small dictionary (3 keys, 1 value each). I have searched high and low on the web (and on here), but cannot seem to find anything pertaining to replacing a value in a dictionary. I have found the "replace" function, but does not seem to work for dictionaries.

                  所以,这是我的字典:

                  a1 = {"Green": "Tree", "Red": "Rose", "Yellow": "Sunflower"}
                  

                  例如,我将如何查询值Rose"以将其替换为Tulip"?

                  How would I go about querying the value "Rose" to replace it with "Tulip," for example?

                  任何帮助都将不胜感激,即使只是为我指明正确的方向!

                  Any help would be greatly appreciated, even if it is just to point me in the right direction!

                  非常感谢!

                  推荐答案

                  首先必须找到值为 "Rose" 的键:

                  You first must find the key that has the value "Rose":

                  for color, flower in a1.items():
                      if flower == "Rose":
                          a1[color] = "Tulip"
                  

                  这篇关于在 Python 字典中查找和替换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                    <legend id='3YjDM'><style id='3YjDM'><dir id='3YjDM'><q id='3YjDM'></q></dir></style></legend>
                    <i id='3YjDM'><tr id='3YjDM'><dt id='3YjDM'><q id='3YjDM'><span id='3YjDM'><b id='3YjDM'><form id='3YjDM'><ins id='3YjDM'></ins><ul id='3YjDM'></ul><sub id='3YjDM'></sub></form><legend id='3YjDM'></legend><bdo id='3YjDM'><pre id='3YjDM'><center id='3YjDM'></center></pre></bdo></b><th id='3YjDM'></th></span></q></dt></tr></i><div id='3YjDM'><tfoot id='3YjDM'></tfoot><dl id='3YjDM'><fieldset id='3YjDM'></fieldset></dl></div>

                    <small id='3YjDM'></small><noframes id='3YjDM'>

                        <bdo id='3YjDM'></bdo><ul id='3YjDM'></ul>
                          <tfoot id='3YjDM'></tfoot>

                            <tbody id='3YjDM'></tbody>