PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  1. Python For Data Analytics
  2. 1.Python
  3. 2.Python Assignments
  4. Dictionary Assignments

Dictionary Cheatsheet

ex: my_dict = {'name': 'John', 'age': 25, 'city': 'New York'}

  1. .clear(): Removes all items from the dictionary. my_dict.clear() # {}

  2. .copy(): Creates a copy of a dictionary new_dict=my_dict.copy() #{'name':'John', 'age':25, 'city':'New York'}

  3. .get(): Returns the value of a particular key. my_dict.get('age') # 25

  4. .items(): Returns all the items preent int he dictionary as (key,value) pairs. my_dict.items() # (name,john), (age,25),(city,New York)

  5. .keys(): Returns a list of keys in a dictionary my_dict.keys() # [name,age,city]

  6. .values(): Returns a list of values in a dictionary. my_dict.values() # [john,25,new york]

  7. .pop(key): Removes the key value pair from the dictionary. my_dict.pop('age') # {'name': 'John', 'city': 'New York'}

  8. .popitem(): Removes the last key value pair from the dictionary. my_dict.popitem() # {'name': 'John', 'age': 25}

  9. .upate(): Updates a dictionary by adding the items from another dictionary. new_dict={'country':'USA','mob_num':12345} my_dict.update(new_dict) # {'name': 'John', 'age': 25, 'city': ' New York','country':'USA','mob_num':12345}

  10. .setdefault(key,value):Returns the value for a key if it exists. If not, inserts the key with a value of default and returns default. my_dict.setdefault('age', 30) # {'name': 'John', 'age': 25, 'city': 'New York'} my_dict.setdefault('height', 175) # {'name': 'John', 'age': 25, 'city': 'New York','height',175}

  11. .fromkeys():Creates a new dictionary with keys from iterable and values set to value. new_dict =dict.fromkeys(['a', 'b', 'c'], 0) # {'a': 0, 'b': 0, 'c': 0}

PreviousDictionary AssignmentsNextFunction Assignments

Last updated 1 year ago