newFlatDict

outputting.newFlatDict(store, selectKeys=None, labelPrefix=u'')[source]

Takes a list of dictionaries and returns a dictionary of 1D lists.

If a dictionary did not have that key or list element, then ‘None’ is put in its place

Parameters:
  • store (list of dicts) – The dictionaries would be expected to have many of the same keys. Any dictionary keys containing lists in the input have been split into multiple numbered keys
  • selectKeys (list of strings, optional) – The keys whose data will be included in the return dictionary. Default None, which results in all keys being returned
  • labelPrefix (string) – An identifier to be added to the beginning of each key string.
Returns:

newStore – The new dictionary with the keys from the keySet and the values as 1D lists with ‘None’ if the keys, value pair was not found in the store.

Return type:

dict

Examples

>>> store = [{'list': [1, 2, 3, 4, 5, 6]}]
>>> newFlatDict(store)
OrderedDict([('list_[0]', [1]), ('list_[1]', [2]), ('list_[2]', [3]), ('list_[3]', [4]), ('list_[4]', [5]), ('list_[5]', [6])])
>>> store = [{'string': 'string'}]
>>> newFlatDict(store)
OrderedDict([(u'string', ["u'string'"])])
>>> store = [{'dict': {1: {3: "a"}, 2: "b"}}]
>>> newFlatDict(store)
OrderedDict([(u'dict_1_3', ["u'a'"]), (u'dict_2', ["u'b'"])])