Path: blob/master/Python core/Data Structures with Python.ipynb
3074 views
1. Lists
Concept: Lists are ordered collections of items, which can be of different types. Lists are mutable, meaning you can change their content.
2. Tuples
Concept: Tuples are similar to lists, but they are immutable, meaning their content cannot be changed after creation.
3. Dictionaries
Concept: Dictionaries are unordered collections of key-value pairs. Keys must be unique and immutable.
4. Sets
Concept: Sets are unordered collections of unique items. They are useful for operations like union, intersection, and difference.
Example:
5. Queues (using collections.deque)
Concept: Queues are collections used to manage data in a First-In-First-Out (FIFO) manner.
6. Stacks (using a list)
Concept: Stacks are collections that follow Last-In-First-Out (LIFO) principles.
Stacks
Stacks follow the Last-In-First-Out (LIFO) principle. Here’s how you can work with them:
Example 1: Balancing Parentheses
Concept: Check if a string of parentheses is balanced using a stack.
Example 2: Implementing a Stack using Linked List
Concept: Create a stack using a custom linked list.
Queues
Queues follow the First-In-First-Out (FIFO) principle. Here’s how you can work with them:
Example 1: Implementing a Queue using Two Stacks Concept: Use two stacks to implement a queue.
Example 2: Using queue.Queue for Thread-Safe Queue Operations
Concept: Use Python’s built-in queue.Queue for thread-safe queue operations.
Quick Practice
Employee Data Management System
Create a Python program that manages and processes employee data using various data structures. The system should perform the following operations
Add New Employees: Store employee details (ID, name, age, department, salary) in appropriate data structures (use dictionary for storing employee details).
Employee Search by ID: Allow users to search for an employee by their ID (use dictionary lookup for efficient search).
Sort Employees by Salary: Sort and display employees based on their salary in descending order (use list of tuples for sorting).
Remove Duplicate Employees: Ensure there are no duplicate entries (use set to remove duplicate employee IDs).
Department-wise Employee Details: Organize and display employees department-wise (use dictionary of lists where keys are department names and values are lists of employees).
Add Multiple Employees using Stack: Implement a stack to allow adding multiple employees. When all employees are added, display the stack in reverse order to show the order in which employees were added.
Queue for Employee Exit: Implement a queue to manage employees who are leaving the organization. Add employees to the queue as they leave, and show the order in which they exit.