Animated Python: Dictionaries and Most Common Elements

Pubblicato il: 02 gennaio 2023
sul canale di: Concepts Illuminated
1,232
34

This video animates the execution of a short Python program that finds the most common letter in a user-provided sentence. Viewers can see how the computer executes the code step by step and see the contents of the variables change as the computer executes the operations. The key components illustrated are for each loops, dictionaries, lists, conditionals, and variables. The code is broken down into two coding patterns, the "count" pattern and the "find largest" pattern.

Another way to visualize code running is https://pythontutor.com (which also has versions for C++, Java, and other programming languages).

Technical note:
As of Python 3.7, dictionaries will iterate through keys in the same order they were added to the dictionary. Prior to that, the key order was unspecified. (https://stackoverflow.com/a/39980744/...)
I chose to make my animated dictionary store the keys in alphabetical order, as I thought that would be more intuitive and similar to a "tree map" data structure.

Playlist of Visualizations:
   • Animated Python Code: Visualizing Computer...  

Animations made by Kaylee L with Manim Community edition (https://www.manim.community/)
https://github.com/kjlubick/manim_ace

Narration by James K. Background music from YouTube Audio Library (   / audiolibrary  )
Wager With Angels by Nathan Moore
Tinker Time by Nathan Moore

0:00 Intro - Finding the most common element
0:33 Execution begins with "pepperoni pizza"
1:09 First for each loop begins iterating over prose string
1:57 Add first key-value pair to the dictionary
3:14 Update existing key-value pair in the dictionary
4:55 End of first for each loop
5:29 Second for each loop begins iteration over char_count dictionary
8:03 Handling a tie for most common letter
9:08 Largest count is found
9:49 End of second for each loop
10:06 Reusable steps are coding patterns


In questa pagina del sito puoi guardare il video online Animated Python: Dictionaries and Most Common Elements della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Concepts Illuminated 02 gennaio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,232 volte e gli è piaciuto 34 spettatori. Buona visione!