Python Basics-Day 2 Learning Note-dictionary Dictionary

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.