Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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}
 
PREVIOUS NEXT
Tagged: #python #dictionary #dynamic #key
ADD COMMENT
Topic
Name
8+3 =