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
On this page of the site you can watch the video online Real-world Python code optimizations with a duration of hours minute second in good quality, which was uploaded by the user Solve Computer Science 04 November 2023, share the link with friends and acquaintances, this video has already been watched 22 times on youtube and it was liked by 0 viewers. Enjoy your viewing!