Skip to main content

system.kanoa.utilities.convertListToDict(dictList, key:)

Given a list of dictionaries, this function will convert it to a dictionary with the key value being the passed key from the dictionary


Parameters

dictList List of Dictionaries: list of dictionaries
key: String: i.e. 'scheduleBlockId'


Returns

convertedDict dictionary


Example

dictList = [{'assetName': 'Line 1', 'assetId': 5}, {'assetName': 'Line 2', 'assetId': 6}]
print system.kanoa.utilities.convertListToDict(dictList, 'assetName')
> {'Line 2': {'assetId': 6, 'assetName': 'Line 2'}, 'Line 1': {'assetId': 5, 'assetName': 'Line 1'}}