Search code examples
pythonpython-3.xlistdictionarymove

Move Python Dictionary From A Dictionary to Another


I am making a game in Python and am storing dictionaries in lists as items:

equipped = {}

swords = {
        'wooden_sword': {'name': 'Wooden Sword', 'dmg': 1}
}

How would I move the wooden_sword item into the equipped lists.

(If i am not using correct terminology feel free to edit)


Solution

  • Assuming your "equipped" is a dictionary (signified by the fact you used curly brackets) you would do it like this:

    equipped.update({'wooden_sword':swords['wooden_sword']})
    del swords['wooden_sword']