I have the following dictionary:
SEC_DICT = {
'equitiesa': 'MC',
'equitiesab': 'MC',
'etfsa': 'ETF',
'etfsab': 'ETF',
'etfsabc': 'ETF',
'maba': 'MA',
'mabab': 'MA',
}
I want to edit or create a new dictionary that that everything starting with equities
for example maps to MC
, so something like SEC_DICT['equitiesblahblahblah']
would map to MC
. Similar with etf
and mab
in the above dictionary.
The one catch is that the SEC_DICT
is referrenced in many many places, so I would ideally not want to create something separate, because this would mean changing things in all places which reference this dictionary.
Is this possible?
For example, if I have the following function:
classify_sec():
a = 'equitieshelloworld'
b = 'equitiesblahblahblah'
y = SEC_DICT[a]
z = SEC_DICT[b]
return y, z
I would expect the above to return MC
, MC
.
May a dictionary is NOT the right data_structure, because I don't want to list out all of the possibilities as keys, because in fact I don't know what the input is, I just want a generic structure where the mapping is something like: 'equities....' -> 'MC' for example.