-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
A Hash Table is a data structure that stores data in key-value pairs. In Python, the built-in dict
(dictionary) is the most common way to implement a hash table.
Hash tables use a hash function to map keys to a specific index where the value is stored.
# Create a hash table (dictionary)
students = {
"101": "Alice",
"102": "Bob",
"103": "Charlie"
}
print(students["102"]) # Output: Bob
✅ Keys can be strings, numbers, or tuples
✅ Values can be of any data type
students["104"] = "David"
students["103"] = "Eve"
del students["101"]
for key, value in students.items():
print(key, ":", value)
Method | Description |
---|---|
dict.get(key) |
Returns value for key (or None ) |
dict.keys() |
Returns all keys |
dict.values() |
Returns all values |
dict.items() |
Returns all key-value pairs |
dict.pop(key) |
Removes item by key |
key in dict |
Checks if key exists |
print(hash("apple")) # Outputs an integer (hash value)
Python internally uses this hash value to store keys efficiently.
Storing user profiles
Phonebooks
Caching
Counting items (frequency maps)
Lookup tables
Q1. Write a Python program to create a dictionary of employee ID → name.
Q2. Write a Python program to add a new employee to the dictionary.
Q3. Write a Python program to update the name of an existing employee.
Q4. Write a Python program to delete an employee using del
keyword.
Q5. Write a Python program to check if the key "105"
exists in the dictionary.
Q6. Write a Python program to use a loop to print all keys and values in the dictionary.
Q7. Write a Python program to get the value for key "104"
using .get()
.
Q8. Write a Python program to list all keys using the .keys()
method.
Q9. Write a Python program to remove an item from the dictionary using .pop()
.
Q10. Write a Python program to count the number of items in the dictionary using len()
.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms