Skip to content

Spirit Yatra

  • Home
  • Entertainment
  • Finance
  • School
  • Journey
  • Product
  • Crypto-Currency

Learning Python -Dictionaries

June 28, 2020 by Stilgar

Continuing with my notes on learning Python. A brief overview of Dictionaries in Python from the Python Dev Bootcamp.

  • Are unordered mappings
  • Key-value pair
  • Do not need to know the exact index position
  • Just need to know the key in order to know the value
  • Uses curly braces and colons to signify the keys and their associated values
  • {‘key1′:’value1′,’key2′:’value2’}
  • Dictionaries are unordered and cannot be sorted.
    • Cannot sort a dictionary
  • Lists on the other hand can be retrieved by location
  • Dictionaries can hold multiple data types include holding lists, or a dictionary within a dictionary
  • Calling a list within a key
    • d = {‘k1′:123,’k2′:[0,1,5],’k3’:{‘insideKey’:100}}
    • d[‘k2’][2]
    • You get 5
  • Appending to a dictionary
    • d[‘key4’] = 300
  • Overwrite
    • d[‘k2’]=26
  • Additional Functions
    • .keys() – shows you a list of keys in the dictionary
    • .values() – shows you the list of values in the dictionary
    • .items() – shows you the list of pairings
    • dict_items([(‘k1’, ‘New Number’), (‘k2’, [0, 1, 5]), (‘k3’, {‘insideKey1’: 100, ‘insidekey2’: 125}), (‘k4’, 75.5)])
      • ^ Shown as a Tuple

How I got into Learning to Code in Python.

Post navigation

Previous Post:

String Formatting for Printing with Python

Next Post:

How to Use Lists in Python Notes

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • My Recent Experience With Trading 0-Day Options February 21, 2025
  • Leveraging AI Tools to Start Working on New Projects February 18, 2025
  • How I Went Through a Javascript 1-Hr Tutorial on Youtube July 12, 2020
  • How to do File Import in Python Notes July 11, 2020
  • Will Learn Javascript Starting This Week July 11, 2020

About Spirit Yatra

This site chronicles my life journey – my challenges, joys, daily mundane activities and observations.

© 2025 Spirit Yatra | Built using WordPress and SuperbThemes