Answers for "python dictionary dynamic key"

0

python dictionary dynamic key

# Dynamically naming Dictionary key, value item
dictionaryName['static_string_' + stringVariable] = otherVariable

# Example
dictOne = {}
strAnimal = 'dogOne'
intAge = 7

dictOne['age_of_' + strAnimal] = intAge
# Result
{'age_of_dogOne': 7}
Posted by: Guest on July-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language