Python
Python Basics
- Introduction to Python and Its History
- Python Syntax and Indentation
- Python Variables and Data Types
- Dynamic and Strong Typing
- Comments and Docstrings
- Taking User Input (input())
- Printing Output (print())
- Python Operators (Arithmetic, Logical, Comparison)
- Type Conversion and Casting
- Escape Characters and Raw Strings
Data Structures in Python
- Lists
- Dictionaries
- Dictionary Comprehensions
- Strings and String Manipulation
- Tuples
- Python Sets: Unordered Collections
- List Comprehensions and Generator Expressions
- Set Comprehensions
- String Formatting
- Indexing and Slicing
Control Flow and Loops
- Conditional Statements: if, elif, and else
- Loops and Iteration
- While Loops
- Nested Loops
- Loop Control Statements
- Iterators and Iterables
- List, Dictionary, and Set Iterations
Functions and Scope
- Defining and Calling Functions (`def`)
- Function Arguments (`*args`, `**kwargs`)
- Default Arguments and Keyword Arguments
- Lambda Functions
- Global and Local Scope
- Function Return Values
- Recursion in Python
Object-Oriented Programming (OOP)
- Object-Oriented Programming
- Classes and Objects
- the `__init__()` Constructor
- Instance Variables and Methods
- Class Variables and `@classmethod`
- Encapsulation and Data Hiding
- Inheritance and Subclasses
- Method Overriding and super()
- Polymorphism
- Magic Methods and Operator Overloading
- Static Methods
- Abstract Classes and Interfaces
Python Programs
- Array : Find median in an integer array
- Array : Find middle element in an integer array
- Array : Find out the duplicate in an array
- Array : Find print all subsets in an integer array
- Program : Array : Finding missing number between from 1 to n
- Array : Gap and Island problem
- Python Program stock max profit
- Reverse words in Python
- Python array duplicate program
- Coin change problem in python
- Python Write fibonacci series program
- Array : find all the pairs whose sum is equal to a given number
- Find smallest and largest number in array
- Iterate collections
- List comprehensions
- Program: Calculate Pi in Python
- String Formatting in Python
Python deque
Elevate your coding journey with Python deque—a game-changer in data management. Learn how to harness dynamic data structures and code like a pro.
'''use case for using the deque data structure in Python: solving the "Maximum of All Subarrays of Size K" problem. In this problem, you are given an array of integers and a window size k.You need to find the maximum element in each subarray of size k as the window slides through the array.
Here's a Python code example using the deque data structure to solve this problem:'''
from collections import deque
def max_in_subarrays(arr, k): result = [] # To store the maximum values of each subarray dq = deque() # To store indices of elements within the current window
for i in range(len(arr)): # Remove indices of elements that are out of the current window while dq and dq[0] < i - k + 1: dq.popleft()
# Remove indices of elements that are smaller than the current element while dq and arr[dq[-1]] < arr[i]: dq.pop()
dq.append(i) # Add the current element's index
# Start adding maximum values to the result once the window is of size k if i >= k - 1: result.append(arr[dq[0]])
return result
# Example usagearr = [1, 3, -1, -3, 5, 3, 6, 7]k = 3result = max_in_subarrays(arr, k)print(result) # Output: [3, 3, 5, 5, 6, 7]