Dictionary expression: {key:value}
- Value can be a string, list, or disctionary. Layered nesting, e.g multi-layer menus
- The print result of dictionary is unordered. Because you can find the value content by key, all without using the subscript as a list.
- Key must be unique and inherently repetitive.
Dataset = { 'Equity Fund':'Deep Value', 'Balanced Fund':'Market oriented with a growth bias', 'Fixed Income Fund': ['government Bond','Financial Notes','Credit Bond','MBS'],}
Print (Dataset)
{' Equity Fund ': ' Deep value ', ' Balanced Fund ': ' Market oriented with a growth bias ', ' Fixed Income Fund ': [' Government bon d ', ' financial Notes ', ' Credit Bond ', ' MBS '}
Add to
dataset["Alternative Investment"] = ' REITS ' # Add key
Print (Dataset)
{' Equity Fund ': ' Deep value ', ' Balanced Fund ': ' Market oriented with a growth bias ', ' Fixed Income Fund ': [' Government bon d ', ' financial Notes ', ' Credit Bond ', ' MBS ', ' Alternative Investment ': ' REITS '}
Modify
dataset["Equity Fund"'fundamental growth'
dataset[' Fixed Income Fund '][1] = ' MTN '
Print (Dataset)
{' Equity Fund ': ' fundamental growth ', ' Balanced Fund ': ' Market oriented with a growth bias ', ' Fixed Income Fund ': [' government bond ', ' MTN ', ' Credit Bond ', ' MBS '], ' Alternative investment ': ' REITS '}
Delete
del dataset['Equity Fund']print(Dataset)
Or
Dataset.pop ("Equity Fund"print(Dataset)
or random Delete
Dataset.popitem ()
Find
Python Basics-Day 2 Learning Note-dictionary Dictionary