Real-world Python code optimizations

Pubblicato il: 04 novembre 2023
sul canale di: Solve Computer Science
22
0

In this video I explain the optimizations for the upcoming version of md-toc (8.2.1). You'll see an in-depth analysis about some design decisions.

I'll talk about list comprehensions, type annotations, dictionaries and hash functions

md-toc is a Python program capable of generating clickable table of contents for markdown files.

Links

md-toc: https://github.com/frnmst/md-toc
PEP 589 – TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys: https://peps.python.org/pep-0589/
PEP 3107 – Function Annotations: https://peps.python.org/pep-3107/
TimeComplexity - Python Wiki: https://wiki.python.org/moin/TimeComp...
Memory-usage of dictionary in Python? - Stack Overflow: https://stackoverflow.com/questions/6...

CHAPTERS

0:00 Intro
0:26 Transform repeated lines of code into a for loop
1:41 Transform the for loop into a list comprehension using the assignment operator (PEP 572): in this case the list comprehension is not the best solution
3:08 Having a look at some examples of the assignment operator (PEP 572)
3:41 Complex typing annotations: passing from manually checking the variable types to simple type annotations. This saves lots of boliterplate code
4:32 PEP 484: Type Hints. Seeing various examples in the document and in md-toc's code
5:37 The new TypedDict definitions in md-toc and the `typing` Python documentation examples
8:02 Caveats for TypedDict definitions: to be valid TypedDict class attributes, the dictionary keys must have the same properties of normal Python variables
9:17 Overview of PEP 589
9:43 For a for loop to a dict comprehension
10:41 Using a hash function in the key before saving a key-value in a dict: improve memory usage by potentially a lot at the cost of some speed. Example that compares a normal key with a hashed key in terms of memory usage
14:55 Outro

#markdown #md-toc #python #solvecomputerscience


In questa pagina del sito puoi guardare il video online Real-world Python code optimizations della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Solve Computer Science 04 novembre 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 22 volte e gli è piaciuto 0 spettatori. Buona visione!