Python Classroom notes 04/May/2025

Pythonic

list comprehensions

  • Provide a concise way to create lists base on existing list by applying expressions and filtering conditions
  • list comprehension syntax
[ expression for item in iterable if condition ]

set comprehensions

  • similar to list comprehensions but produces a set instead of list
{ expression for item in iterable if condition }

dictionary comprehensions

  • similar to list and set, but you define both key and value for each element
{ key_expression: value_expression for item in iterable if condition }

Exercise:

  • Try to find all the files in your downloads folder which are greater than 1 MB (python)
path = Path(r"C:\Users\Dell\Downloads")
[ item for item in Path(r"C:\Users\Dell\Downloads").rglob("*") if  item.is_file() and item.stat().st_size > 1048576 ]

Type Hinting

  • Type hinting uses the typing module to specify the expected types of function arguments and return values Refer Here for cheatsheet and Refer Here for article
  • Refer Here for the jupyter notebook

Code coverage

  • Refer Here for how to do code coverage
  • Code coverage gives us metrics on how much of development code is covered by test code
  • Refer Here for the changes

Building cli applications in Python

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%