How do I copy values from one dictionary to a second dictionary with new keys?
<p>I am trying to make weapons in my game exclusive to certain classes. I have an item database in form:</p>

<pre><code>itemsList = {
1: {"name": "Padded Armor",  "armor": 1,  "value": 5, "class": "light"},
2: {"name": "Leather Armor",  "armor": 2,  "value": 10, "class": "light"},
3: {"name": "Studded Leather Armor",  "armor": 3,  "value": 25, "class": "light"},
...
19: {"name": "Dagger", "damage" : int(random.randrange(1, 4)), "value": 2, "Type": "Dagger"},
20: {"name": "Dagger + 1", "damage" : int(random.randrange(1, 4) + 1), "value": 200, "Type": "Dagger"},
21: {"name": "Dagger + 2", "damage" : int(random.randrange(1, 4) + 2), "value": 750, "Type": "Dagger"},
22: {"name": "Dagger + 3", "damage" : int(random.randrange(1, 4) + 3), "value": 2000, "Type": "Dagger"}
}
</code></pre>

<p>I am going to import, if a class can equip a certain weapon, to a new dictionary, </p>

<pre><code>character.canEquipWeapon = {}
</code></pre>

<p>I would like to assign the name, damage, value, and type to a new set of keys in the dictionary, only, I would like to add only certain subsets (daggers, maces, swords) to certain classes. </p>

<p>I have tried </p>

<pre><code>character.canEquipWeapon.update(itemsList[5])
</code></pre>

<p>and that just overwrites the dictionary with each new value. How do I go about doing this?</p>

<p>How do you feel about making <code>itemsList</code> an array instead of a dict? Seems like you're using it as an array anyhow. That way, you could do something like</p>

<pre><code>itemsList2 = [weapon for weapon in itemsList if weapon.type == "dagger"]
</code></pre>

<p>or if the weapon types are stored in, say, <code>character.weaponTypes</code></p>

<pre><code>itemsList2 = [weapon for weapon in itemsList if weapon.type in character.weaponTypes]
</code></pre>

python dictionary key