0 (0 Ratings)

Intermediate Python Programming

Categories Programming, Python

What I will learn?

  • Work confidently with advanced data structures, files, and reusable modules in Python.
  • Build efficient, clean code using list comprehensions, lambda functions, and custom exceptions.
  • Develop real-world tools with object-oriented programming, APIs, virtual environments, and command-line interfaces.
  • Automate tasks and boost performance using Python libraries, multithreading, and a hands-on mini project.

Course Curriculum

Advanced Data Structures: Lists, Tuples, Sets, and Dictionaries
In this module, you will learn how to store and manipulate collections of data in Python, using the most common built-in types. These advanced data structures underpin efficient code and robust applications, making them essential for any intermediate Python programmer.

  • Introduction
  • Lists: Ordered, Mutable Collections
  • Tuples: Immutable Sequences
  • Sets: Unordered Unique Collections
  • List vs Tuple vs Set
  • Dictionaries: Key-Value Mappings
  • Summary

List Comprehensions and Lambda Functions
If you have ever found yourself writing loops to transform or filter lists, you will soon see how these two techniques can make your code more concise and legible. By the end of this module, you will know when and how to use list comprehensions and lambda functions together to write elegant, efficient Python. Understanding List Comprehensions List comprehensions provide a compact way to build new lists by applying an expression to each item in an existing iterable. Syntax and Components A basic list comprehension looks like this: [ expression for item in iterable if condition ] - expression: the operation applied to each item - item: the variable representing each element - iterable: any sequence such as a list, tuple or range - condition (optional): a filter that selects which items get included Simple Examples Create a list of squares: squares = [ x**2 for x in range(1, 11) ] print(squares) # [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] Filter for even numbers only: evens = [ x for x in range(1, 11) if x % 2 == 0 ] print(evens) # [2, 4, 6, 8, 10] Each example uses a single line of code instead of a multi-line loop, improving readability. Exploring Lambda Functions Lambda functions are anonymous, single-expression functions defined with the lambda keyword. They are useful when you need a small function for a short period and do not plan to reuse it. Syntax lambda arguments: expression - arguments: comma-separated inputs - expression: computation that returns a value When to Use Lambda Functions - In higher-order functions such as map(), filter() or sorted() - Within list comprehensions when a simple transformation is required - For quick callbacks or key functions in sorting Combining List Comprehensions with Lambda Functions By calling a lambda inside a list comprehension, you can perform custom transformations in one concise statement. Mapping with Lambda in a List Comprehension Convert a list of Fahrenheit temperatures to Celsius: fahrenheit = [32, 50, 68, 86, 104] celsius = [ (lambda f: (f - 32) * 5/9)(temp) for temp in fahrenheit ] print(celsius) # [0.0, 10.0, 20.0, 30.0, 40.0] Explanation: - Define an anonymous function (lambda f: (f - 32) * 5/9) - Immediately call it with each temp from the fahrenheit list - Build a new celsius list with the converted values Filtering with Lambda in a List Comprehension Select odd numbers by wrapping a lambda in an if clause: numbers = list(range(1, 11)) odds = [ n for n in numbers if (lambda x: x % 2 == 1)(n) ] print(odds) # [1, 3, 5, 7, 9] Explanation: - The lambda (lambda x: x % 2 == 1) returns True for odd values - The if clause filters numbers accordingly Real-World Scenario: Data Cleaning Imagine you have a list of product codes with trailing spaces. Use a lambda and list comprehension to strip whitespace: raw_codes = ["A123 ", " B456", "C789 "] clean_codes = [ (lambda s: s.strip())(code) for code in raw_codes ] print(clean_codes) # ['A123', 'B456', 'C789'] This one-liner removes unwanted spaces and returns a clean list. Performance Considerations In many cases, list comprehensions are faster than using map() with a lambda, because they execute in C-level loops. Reserve map() for situations where you already have a named function to apply. Best Practices and Tips - Use list comprehensions for simple loops that build lists - Reserve lambdas for very short, throwaway functions - For more complex logic, define a named function with def - Keep expressions inside list comprehensions readable; break out code if it becomes too long Further Reading - Python’s official guide to list comprehensions - Python’s reference on lambda expressions Summary In this lesson you have: - Seen how list comprehensions replace loops for building lists - Learned the syntax and use cases for lambda functions - Combined both techniques to transform and filter data in one line - Explored real-world examples for data conversion and cleaning Apply these tools in your own code to write Python that is both clear and concise.

Working with Modules and Packages
Have you ever started a Python script only to find your workspace cluttered with dozens of functions and variables? Learning how to work with modules and packages will help you organise code into self-contained units and reuse your work across projects.

Object – Oriented Programming (OOP) in Python

Classes, Objects, Inheritance and Encapsulation

File Handling with Context Managers (with statement)

Error Handling and Custom Exceptions

Working with APIs and JSON Data

Introduction to Regular Expressions (re module)

Intermediate Automation with os, shutil and glob

Introduction to Python Virtual Environments (venv)

Using argparse for Command Line Tools

Multithreading and Multiprocessing Basics

Mini Project: Building a CLI Tool or Automation Script

Student Ratings & Reviews

No Review Yet
No Review Yet
Free
Free access this course

A course by

Requirements

  • Basic understanding of Python syntax, variables, and functions is expected
  • You will need a computer with Python installed (Windows, macOS, or Linux)
  • Access to a code editor such as VS Code or PyCharm is recommended
  • No prior experience with object-oriented programming is required

Target Audience

  • Beginners who are comfortable with Python basics and want to move to the next level
  • Developers looking to strengthen their Python coding skills
  • Data enthusiasts and automation testers who want to script complex workflows
  • Students preparing for technical job interviews or coding assessments

Want to receive push notifications for all major on-site activities?