I have a fairly basic question regarding python lists/dictionaries which I would like some help on.
I have some data relating to electric vehicles which have different characteristics. Each EV has an:
- ID e.g. 12345
- A battery size e.g. 24
- A state of charge for each five minute period of the day e.g. 00:05:00 : 1; 00:10:00 : 0.95
How best do I go about this? I had been trying various combinations of lists/dicts but can’t quite get it to work. I’d like to be able to access the data by e.g.:
EV['ID'][2]['Batt']['SOC'][5] which would return e.g. 0.95 or
EV[12345]['Batt']['SOC'][5]
My latest attempt was:
EV = defaultdict(lambda: defaultdict(dict))
EV['ID']['Batt']['Time']=[]
EV['ID']['Batt']['SOC']=[]
EV['ID']['Batt']['Size'] = 24
However this didn’t allow for the entry of multiple IDs which are in another list admin[‘ID’]. It yielded:
{'ID': defaultdict....,{'Batt':{'SOC:[], 'Size':24, 'Time':[]}}}}
I would appreciate your help!
1 Answer