<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python-Advanced-Python-Data-Structures on Janusworx</title><link>https://janusworx.com/tags/python-advanced-python-data-structures/</link><description>Recent content in Python-Advanced-Python-Data-Structures on Janusworx</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>feedback@janusworx.com (Mario Jason Braganza)</managingEditor><webMaster>feedback@janusworx.com (Mario Jason Braganza)</webMaster><copyright>© 2026, Mario Jason Braganza</copyright><lastBuildDate>Wed, 22 Jul 2020 17:48:09 +0530</lastBuildDate><atom:link href="https://janusworx.com/tags/python-advanced-python-data-structures/index.xml" rel="self" type="application/rss+xml"/><item><title>A Hundred Days of Code, Day 013, Day 14 - Python, Advanced Data Structures, Done!</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-013-day-14-python-advanced-data-structures-done/</link><pubDate>Wed, 22 Jul 2020 17:48:09 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-013-day-14-python-advanced-data-structures-done/</guid><description>&lt;p&gt;Notes and experiences for yesterday and today.&lt;br&gt;
I ‘wasted’ a lot of time, again, struggling with exercises yesterday and ended up being too zombied to even write the summary post.&lt;br&gt;
Have been much smarter about it today.&lt;br&gt;
Stopped after about 30 mins and copied and tried to understand the solution.&lt;/p&gt;
&lt;!-- TEASER_END --&gt; 

&lt;h3 class="relative group"&gt;Notes
 &lt;div id="notes" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#notes" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;List of Dictionaries&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Just more convenient than a list of lists, not particularly faster&lt;/li&gt;
&lt;li&gt;Make it more flexible.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Dictionary of dictionaries&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Think beforehand of what your keys are going to be.&lt;/li&gt;
&lt;li&gt;Looking in them, faster than lists&lt;/li&gt;
&lt;li&gt;The tradeoff is more memory usage&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Dictionary of Lists&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Works when you need disparate elements to work with later. Those can be stored as dictionary values, in a list form.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Part 3&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Decimals&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To have something sane between integers and crazy floats.&lt;/li&gt;
&lt;li&gt;I import the Decimal class and then create objects, like so&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;decimal&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;0.1&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;0.2&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;I create them from &lt;em&gt;strings&lt;/em&gt; not floats, just like I would &lt;code&gt;int&lt;/code&gt; strings.&lt;/li&gt;
&lt;li&gt;It has various methods I can call on the Decimal object.
&lt;ul&gt;
&lt;li&gt;Stuff like &lt;code&gt;getcontext&lt;/code&gt; with has a method to set the precision of units after the decimal point.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Helpful if you need precision at a certain level.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Named Tuples&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A very handy way of calling values in a tuple by sensible names, just like dictionaries&lt;/li&gt;
&lt;li&gt;Very handy instead of heavyweight dictionaries.&lt;/li&gt;
&lt;li&gt;Create them like so&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;namedtuple&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;namedtuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Person&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;first&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;last&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;me&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Jason&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Braganza&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Doing a &lt;code&gt;me.first&lt;/code&gt; will get me &lt;code&gt;Jason&lt;/code&gt;, just like a dictionary.&lt;/li&gt;
&lt;li&gt;I can still refer to the tuples with the numeric indices.&lt;/li&gt;
&lt;li&gt;I can do a &lt;code&gt;._replace&lt;/code&gt; to replace values, if I want to. &lt;code&gt;me._replace(first ='Mario')&lt;/code&gt;. It just returns a new object with the same name, which I can choose to catch in a &lt;em&gt;new&lt;/em&gt; variable.&lt;/li&gt;
&lt;li&gt;Better for readability.&lt;/li&gt;
&lt;li&gt;Basic uses. The moment I want to twiddle with it too much, I know I should just make my own classes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;defaultdict&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A variation/improvement on the normal dictionary.&lt;/li&gt;
&lt;li&gt;We want a dictionary, with default values.&lt;/li&gt;
&lt;li&gt;When I check for the presence of a key, if it does not exist it’ll get created with a default value.&lt;/li&gt;
&lt;li&gt;We give it a function or a class, that will run, be called everytime a key does not exist.&lt;/li&gt;
&lt;li&gt;So I could pass it basic primitives, like a list with no entries and it will return an empty list for a value everytime, there is not one. Or saying int, in which case it will create a key with 0 for a value&lt;/li&gt;
&lt;li&gt;Create them like so&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;defaultdict&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;defaultdict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;So now when I do &lt;code&gt;d['a']&lt;/code&gt;, it well check for key &lt;code&gt;a&lt;/code&gt;. If it does not exist, it will create it, and give it a value of 0 by running the int function with no arguments.&lt;/li&gt;
&lt;li&gt;I can use any function or callable, as long as it has no arguments.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;OrderedDict&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No need to use it anymore&lt;/li&gt;
&lt;li&gt;But handy in case I am looking at old code.&lt;/li&gt;
&lt;li&gt;Regular dictionaries order stuff chronolgically as of Python 3.7.&lt;/li&gt;
&lt;li&gt;Which is what ordered dictionaries used to do.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Counter&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;from collections import Counter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;if I pass an Counter dictionary an iterable, it will create a dictionary with the occurrence of each element.&lt;/li&gt;
&lt;li&gt;if I go &lt;code&gt;c = Counter[10, 10, 20, 50, 60, 60, 80, 80, 80, 90']&lt;/code&gt;, then I get a dictionary like &lt;code&gt;Counter({10: 2, 20: 1, 50: 1, 60: 2, 80: 3, 90: 1})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I can also do a most common method to get the most frequently used elements. &lt;code&gt;c.most_common()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Enums&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;from enum import Enum&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Create ’em like&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ColorEnum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Red&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Blue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Green&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Matches symbolic labels / names to numeric values.&lt;/li&gt;
&lt;li&gt;If &lt;code&gt;a = ColorEnum.Red&lt;/code&gt; and &lt;code&gt;b=ColorEnum.Red&lt;/code&gt; then they would both be equal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 class="relative group"&gt;Learning / Feedback/ Experiences from doing exercises
 &lt;div id="learning--feedback-experiences-from-doing-exercises" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#learning--feedback-experiences-from-doing-exercises" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Reuven keeps harping on the fact, that I need to &lt;em&gt;think&lt;/em&gt; things through.
&lt;ul&gt;
&lt;li&gt;Is this how you want to build things?&lt;/li&gt;
&lt;li&gt;What are the ramifications?&lt;/li&gt;
&lt;li&gt;What if you want to change up things or if things are expected to grow exponentially in the future?&lt;/li&gt;
&lt;li&gt;Think! Be itentional. Design accordingly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Caught myself frequently initalising a total in a loop and then wondering why I would not get the actual total :)&lt;/li&gt;
&lt;li&gt;Now my approach, kinda matches what Reuven does. Which means, I am beginning to write some sane code :)&lt;/li&gt;
&lt;li&gt;Finished with this course. And on to the next one. Planning, building in margin and working at it a little bit everyday helping a lot!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/python-advanced-python-data-structures/" &gt;Read all about my Python advanced data structures journey here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>A Hundred Days of Code, Day 012 - Python, Advanced Data Structures continued</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-012-python-advanced-data-structures-continued/</link><pubDate>Mon, 20 Jul 2020 16:21:04 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-012-python-advanced-data-structures-continued/</guid><description>&lt;p&gt;Ok! Had a nice refreshing break, yesterday being Sunday.&lt;br&gt;
Back to work today!&lt;br&gt;
If today’s notes, feel a little light, that’s because I was struggling with exercises.&lt;/p&gt;
&lt;!-- TEASER_END --&gt;

&lt;h2 class="relative group"&gt;Notes
 &lt;div id="notes" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#notes" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Part 2&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A lightweight solution to classes, if I am just combining all sorts of data structures is the built-in &lt;code&gt;collections&lt;/code&gt;. Some of them could be
&lt;ul&gt;
&lt;li&gt;List of Lists&lt;/li&gt;
&lt;li&gt;List of Tuples&lt;/li&gt;
&lt;li&gt;List of Dictionaries&lt;/li&gt;
&lt;li&gt;Dictionary of Dictionaries&lt;/li&gt;
&lt;li&gt;Dictionary of Lists&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Mostly use them to solve tricky issues. If I find myself using lots of functions, just to deal with these structures, I am better off using classes.
&lt;ul&gt;
&lt;li&gt;These structures also lend themselves to being converted into classes.&lt;/li&gt;
&lt;li&gt;Sometimes it’s just a matter of adding a few methods, et voilà, I have a class!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Lists of lists&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As simple to create as &lt;code&gt;l = [[1,3,2],[4,5,6],[7,8,9]]&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;If I do a &lt;code&gt;l[0]&lt;/code&gt;, I’ll get the first element, the list &lt;code&gt;[1,3,2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To get at the elements inside &lt;em&gt;that&lt;/em&gt; list, I can go &lt;code&gt;l[0][2]&lt;/code&gt; which will give me the number, 3.&lt;/li&gt;
&lt;li&gt;Behind the scenes, &lt;code&gt;l.__getitem__(0).__getitem__(2)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;We can either work with them with indices like up above, or iterate over them, with for loops or comprehensions&lt;/li&gt;
&lt;li&gt;Better to use lists of tuples, if I am dealing with mixed types, specially those that are not apt to change, like records of some sort. Something like a list of details about movies.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

&lt;h2 class="relative group"&gt;Learning / Feedback/ Experiences from doing exercises
 &lt;div id="learning--feedback-experiences-from-doing-exercises" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#learning--feedback-experiences-from-doing-exercises" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learning to think atomically. Learning to break down each exercise into pieces and then learning to organise them in a manner, that I can solve it, step by step.
&lt;ul&gt;
&lt;li&gt;What hints do Reuven’s results show?&lt;/li&gt;
&lt;li&gt;What should I compare first? What will be the aftermath? and so on.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Gave up an exercise after two hours of trying.
&lt;ul&gt;
&lt;li&gt;After peeking at the solution I realised that it was not because of something I forgot or did not practice, but once again, because of something I did not know.&lt;/li&gt;
&lt;li&gt;in this case that there are set operators to use between two iterator objects.instead of crazily stepping through everything like I did below, I could’ve just created a union list run through them.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Just goes to show, there is lots for me to learn. And that there is a lot of tacit knowledge out there. And this I will only be able to figure out by writing lots of code!&lt;/li&gt;
&lt;li&gt;Also (note to self), time your self and be ok with giving up and looking at the solution. I seem to keep thinking that I am wrong or am missing something. Never the fact, that it might be something that I do not know.
&lt;ul&gt;
&lt;li&gt;I am now strictly going to give myself 30 minutes per exercise and then move on.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Lots of mistakes as usual.
&lt;ul&gt;
&lt;li&gt;Wrong indentation, giving weird results.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/python-advanced-python-data-structures/" &gt;Read all about my Python advanced data structures journey here&lt;/a&gt;&lt;/p&gt;</description></item><item><title>A Hundred Days of Code, Day 011 - Python, Advanced Data Structures</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-011-python-advanced-data-structures/</link><pubDate>Sat, 18 Jul 2020 19:14:17 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-011-python-advanced-data-structures/</guid><description>&lt;p&gt;Started with a new &lt;a href="https://store.lerner.co.il/advanced-python-data-structures/" target="_blank" rel="noreferrer"&gt;Reuven Lerner Course, on Advanced Data Structures.&lt;/a&gt;.&lt;br&gt;
Aiming to comfortably finish this in a week.&lt;br&gt;
Notes and experiences, follow.&lt;br&gt;
The course is three parts.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Part 1 - Deep dive into the common data structures&lt;/li&gt;
&lt;li&gt;Part 2 - Combining Data Structures. Lists of lists, Dicts of lists, Tuples of Lists and so forth. How far can I go without classes? Or how can I enhance my classes with this approach?&lt;/li&gt;
&lt;li&gt;Part 3 - Complex data structures, that come with the Python Standard Library. The Collections module, Weak references etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- TEASER_END --&gt; 

&lt;h3 class="relative group"&gt;Notes
 &lt;div id="notes" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#notes" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Part 1&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;id&lt;/code&gt; of a variable shows me where the object in refers to, is located in memory.&lt;br&gt;
If &lt;code&gt;x=5&lt;/code&gt; then the &lt;code&gt;id(x)&lt;/code&gt; will point to where it’s object, here the number 5, is located in memory.&lt;/li&gt;
&lt;li&gt;When I assign a variable to another, what I actually do is assign the new variable to the same objects address. That is all. When I do &lt;code&gt;x = y&lt;/code&gt;, then y will point to 5 too, independent of x. If I set x to something else later, y is not going to follow x. Instead it steadfastly points to 5.&lt;/li&gt;
&lt;li&gt;A simple way to say this is &lt;code&gt;x is y&lt;/code&gt;, where I am &lt;em&gt;not&lt;/em&gt; checking for equality, but rather testing the fact, that both of them point to the same location in memory, or not.&lt;/li&gt;
&lt;li&gt;I can use &lt;code&gt;sys.getsizeof()&lt;/code&gt; to find the size of an object in memory. (how much memory it uses), but it’s a tricky beast. For e.g. when it shows me the size of a list, it shows me the size of the list object. Not the size of the elements it contains. To get that, I need to go check the size of its elements one by one.&lt;/li&gt;
&lt;li&gt;A singleton object (not many in Python) is an object that every time you create a new instance of, from the parent class, it always points back to the same instance. &lt;code&gt;None&lt;/code&gt; is an example in Python.&lt;/li&gt;
&lt;li&gt;Better to create a list using square brackets, rather than assigning them via a string. &lt;code&gt;x = ['a','b','c','d']&lt;/code&gt; works better than going &lt;code&gt;x = list('abcd')&lt;/code&gt;. This obviously matters upon what you are doing and if that is possible to do or not.&lt;/li&gt;
&lt;li&gt;I can tuple-unpack-split a string in various ways. If I go, &lt;code&gt;a, b, *c = s.split[]&lt;/code&gt; it will get the first split item in a, the next one in b, and the rest will be a list in c. But if I want the first and last elements for example and don’t care about the stuff in the middle, I can also go, &lt;code&gt;a, *b, c = s.split()&lt;/code&gt;. I need to play with this. Just realised I could’ve solved a lot of exercises I did in the past, more elegantly if I knew this then.&lt;/li&gt;
&lt;li&gt;If I access an element in a sequence via its index, I will get the element back along with the &lt;em&gt;elements type&lt;/em&gt;, but if I slice a sequence to get just one element back, I get a single element of the &lt;em&gt;sequence’s type&lt;/em&gt;. Very nifty!
&lt;ul&gt;
&lt;li&gt;For example if I access &lt;code&gt;s[0]&lt;/code&gt; in the list &lt;code&gt;['jason', 'braganza']&lt;/code&gt;, then I will get a string &lt;code&gt;jason&lt;/code&gt; back.&lt;/li&gt;
&lt;li&gt;But if I slice and get just the first element with a &lt;code&gt;s[:1]&lt;/code&gt; (get upto, but not including 1), I get a single element &lt;em&gt;list&lt;/em&gt;, &lt;code&gt;['jason']&lt;/code&gt; back.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;If I look up a key &lt;code&gt;z&lt;/code&gt; in a dictionary &lt;code&gt;d&lt;/code&gt; with a &lt;code&gt;d[z]&lt;/code&gt; and it does not exist, then I get a &lt;code&gt;KeyError&lt;/code&gt;. If I want to check keys without noise, I use the &lt;code&gt;get&lt;/code&gt; method on a dictionary. If the key exists, the value is returned. If not &lt;code&gt;None&lt;/code&gt; comes back.
&lt;ul&gt;
&lt;li&gt;I can set keys similarly with the &lt;code&gt;setdefault&lt;/code&gt; key if I want to set keys safely. If I just do &lt;code&gt;d[z] = 100&lt;/code&gt; and z already existed, its value would have gotten trampled and set to 1000. But if I do the samething with a &lt;code&gt;d.setdefault(z, 100)&lt;/code&gt; then it sets it to 100 &lt;em&gt;only&lt;/em&gt; if the key does not exist. If it does, it just returns the old existing value. No harm, no foul.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;If I have two dictionaries and I want the contents of one in the other, then I use the update method. For e.g., I have dictionary a and dictionary b, so I do &lt;code&gt;a.update(b)&lt;/code&gt; and everything from b flows into a.
&lt;ul&gt;
&lt;li&gt;If there is overlap in the keys, then the values get trampled and overwritten.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;I normally cannot add dictionaries, lists, or other sets &lt;em&gt;to&lt;/em&gt; my sets (no &lt;em&gt;unhashable&lt;/em&gt; types allowed), I can freeze a set with &lt;code&gt;frozenset&lt;/code&gt;, which makes it hashable and then add it to my set.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

&lt;h3 class="relative group"&gt;Learning / Feedback/ Experiences from doing exercises
 &lt;div id="learning--feedback-experiences-from-doing-exercises" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#learning--feedback-experiences-from-doing-exercises" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Reuven makes Python sound like a cute animated bear. ‘Python notices and says “Oh, you’re using 256. I’ve aleady got that. Don’t create a new object for that!”’ I wish my interpreter was as helpful 😂&lt;/li&gt;
&lt;li&gt;This course is a lot less structured than the basic courses. It approaches you from the point of view, that you know stuff, you can read and write Python, you have a modicum of intelligence, so here’s a really juicy grab bag of interesting stuff about all the basics you learnt earlier.
&lt;ul&gt;
&lt;li&gt;It’s best to always use f-strings, but if you need to eke performance, can you figure out, what kind of strings are the best? (spoiler, benchmark it)&lt;/li&gt;
&lt;li&gt;While Python lists are expandable, the C structures underyling it are fixed. How does Python let you have flexible, expandable lists then?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;And so on and so forth. So far, this has been &lt;em&gt;fascinating.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/python-advanced-python-data-structures/" &gt;Read all about my Python advanced data structures journey here&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>