-4

In Python I have this kind of expression to deal with:

 alg_error = self.__rec_data[seedict][scanner][CALCULATE][CALCULATE_VALUE]

or

alg_error = self.__rec_data[seedict][scanner][CALCULATE][CALCULATE_VALUE]
alg_comp = self.__rec_data[pers][dict1][DATA][DATA_DICT]

I do not understand this multiple dictionary expression at all, how does it work, what if I assign a value for example

algo_dem_error_path_comp = self.__rec_file_data[pers][scan][DATA][DATA_ERR_PATH_COMP] = "value : 5 " 

Where would five go?

martineau
  • 119,623
  • 25
  • 170
  • 301
whtr
  • 15
  • 8
  • 1
    Look for some basic stuff on Python Dictionaries http://stackoverflow.com/questions/16333296/how-do-you-create-nested-dict-in-python – ZdaR Feb 19 '17 at 18:18

2 Answers2

2

You've got a nested dictionary, i.e. a dictionary where the items themselves are also dictionaries. So each key is finding the corresponding item in that dictionary.

foo = {"A": 1, "B": 2, "C": 3}
bar = {"A:": 2, "B": 4, "C": 6}

baz = {"X": foo, "Y": bar}

print(baz["X"]["A"])
Batman
  • 8,571
  • 7
  • 41
  • 80
0

What you are looking at here is nested dictionaries. Example:

>>> dict1 = {'hello': 'sup'}

>>> dict2 = {}
>>> dict2['first_thing'] = dict1

>>> dict2
{'first_thing': {'hello': 'sup'}}

>>> dict2['first_thing']['hello']
'sup'

>>> dict2['first_thing']['new_key'] = 'heman'

>>> dict2
{'first_thing': {'new_key': 'heman', 'hello': 'sup'}}

So, without going into the details of your specific data structure, hopefully that clears things up a bit.

MrName
  • 2,363
  • 17
  • 31