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 Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube