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 Iterate all Collections
Pair programming is a collaborative approach to software development in which two programmers work together on the same codebase. It is an effective technique for improving code quality, fostering knowledge sharing, and enhancing collaboration between team members. When it comes to iterating over Python collections, there are several options available, and exploring them together in a pair programming session can be a valuable learning experience. Let’s take a look at some of the common Python collections and how to iterate over them:
- Lists:
Lists are ordered collections that can hold elements of different types. To iterate over a list, you can use a for loop:
my_list = [1, 2, 3, 4, 5]
for item in my_list: print(item)
- Tuples: Tuples are similar to lists but are immutable, meaning their elements cannot be modified. Iterating over a tuple follows the same approach as iterating over a list:
my_tuple = (1, 2, 3, 4, 5)
for item in my_tuple: print(item)
- Sets: Sets are unordered collections of unique elements. To iterate over a set, you can use a for loop:
my_set = {1, 2, 3, 4, 5}
for item in my_set: print(item)
- Dictionaries: Dictionaries are key-value pairs where each value is associated with a unique key. To iterate over a dictionary, you can loop over its keys, values, or key-value pairs:
my_dict = {"name": "John", "age": 30, "city": "New York"}
# Iterate over keysfor key in my_dict: print(key)
# Iterate over valuesfor value in my_dict.values(): print(value)
# Iterate over key-value pairsfor key, value in my_dict.items(): print(key, value)
- Strings: Strings in Python are iterable, allowing you to iterate over each character using a for loop:
my_string = "Hello, World!"
for char in my_string: print(char)
These examples cover the basic iteration techniques for commonly used Python collections. However, there are more advanced techniques and specialized iterators available, such as list comprehensions, generator expressions, and the iter
and next
functions. Exploring these concepts further can deepen your understanding of Python’s iteration capabilities.
By pairing up and discussing these examples, you and your programming partner can gain insights, exchange ideas, and reinforce your knowledge of iterating over Python collections. It is also an opportunity to discuss best practices, potential optimizations, and any challenges or questions that arise during the session. Happy pair programming!