python dictionary dynamic key

Solutions on MaxInterview for python dictionary dynamic key by the best coders in the world

showing results for - "python dictionary dynamic key"
Lylia
25 Sep 2019
1# Dynamically naming Dictionary key, value item
2dictionaryName['static_string_' + stringVariable] = otherVariable
3
4# Example
5dictOne = {}
6strAnimal = 'dogOne'
7intAge = 7
8
9dictOne['age_of_' + strAnimal] = intAge
10# Result
11{'age_of_dogOne': 7}
12