{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 5. Dictionary\n", "\n", "Let's dive into the world of dictionaries, a fundamental data structure in Python. We'll cover how to create, access, and manipulate key-value pairs within dictionaries.\n", "\n", "A **dictionary** in Python is an unordered collection of key-value pairs. It's a data structure that allows you to store and retrieve data using unique keys. Each key is associated with a corresponding value. \n", "\n", "We'll learn about the following topics:\n", "\n", " - [5.1. Creating Dictionary](#Creating_Dictionary)\n", " - [5.2. Built-in Dictionary Functions](#Builtin_Dictionary_Functions)\n", " - [5.3. Accessing Dictionary Values](#Accessing_Dictionary_Values)\n", " - [5.4. Dictionary Properties](#Dictionary_Properties)\n", " - [5.5. Dictionary Operators](#Dictionary_Operators)\n", " - [5.6. Built-in Dictionary Methods](#Builtin_Dictionary_Methods)\n", " - [5.7. Nesting Dictionaries](#Nesting_Dictionaries)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n",
"
\n",
"
| Name | \n", "Type in Python | \n", "Description | \n", "Example | \n", "
|---|---|---|---|
| Dictionaries | \n", "dict | \n", "Unordered key:value pairs in { }. | \n", "{'key':10, 'word': 'hello'} | \n", "
| Method | \n", "Description | \n", "
|---|---|
| keys() | \n", "return a list of all keys | \n", "
| values() | \n", "return a list of all values | \n", "
| items() | \n", "return tuples of all items | \n", "
| update(2nd dic) | \n", "Merge two dictionaries | \n", "
| get(key) | \n", "returns the value for a given key | \n", "
| pop(key) | \n", "removes the specified ke0value pair from the dictionary and return the value of the removed key | \n", "
| popitem() | \n", "removes and returns an arbitrary key-value pair from the dictionary as a tuple | \n", "
| clear() | \n", "empties dictionary of all key-value pairs | \n", "