Python Dictionarys
<p>I am stucked with a school project. The following function should set the name of a room in a given dictionary.The rooms dicionary should stay because functions using it.It should randomly set the name of the rom to display it later in another function.</p>

<pre><code>import string
import random

names = ['This', 'happens', 'all', 'the', 'time']
for key, value in rooms.items():
    # do something with value
    rooms[value]["name"] = random.choice(names)
    names.remove(rooms[value]["name"])

room_1 = {"name" : "",
          "description" : """ """,
          "exits" : {"east": "Second" , "south":"Fourth"},
          "items" : []}

room_2 = {"name": "",
          "description" : """ """, 
          "exits" : {"west": "First" , "south":"Fifth" , "east":"Third"},
          "items" : []}

rooms = {"First" : room_1,
         "Second" : room_2,}
</code></pre>

<p>To make the script you posted work, you need to:</p>

<ol>
<li><p>Move the <code>for</code> lop to the end of the script (after you set the value
of <code>rooms</code>). It operates on <code>rooms</code> variable, which must be defined
firs</p></li>
<li><p>Fix the <code>for</code> loop. If you want to modify a value of a dictionary, access it with <code>rooms[key]</code>, not <code>rooms['value']</code>. </p></li>
</ol>

<p>`Something like this:</p>

<pre><code>import random
names = ['This', 'happens', 'all', 'the', 'time']

rooms = {
    "First": {},
    "Second": {},
}

for key in rooms:
    # do something with value
    name = random.choice(names)
    rooms[key]["name"] = name
    names.remove(name)
</code></pre>

python python-3.x dictionary