Finding and replacing a value in a Python dictionary
<p>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!).</p>

<p>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.</p>

<p>So, here is my dictionary:</p>

<pre><code>a1 = {"Green": "Tree", "Red": "Rose", "Yellow": "Sunflower"}
</code></pre>

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

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

<p>Thanks so much!</p>

<p>You first must find the key that has the value <code>"Rose"</code>:</p>

<pre><code>for color, flower in a1.items():
    if flower == "Rose":
        a1[color] = "Tulip"
</code></pre>

python dictionary replace find