Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvariyath committed Nov 1, 2024
2 parents 77ca29a + a65694b commit 8fcaf23
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 504 deletions.
433 changes: 218 additions & 215 deletions README.md

Large diffs are not rendered by default.

457 changes: 227 additions & 230 deletions index.html

Large diffs are not rendered by default.

71 changes: 42 additions & 29 deletions parse.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions pdf/index_for_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h3 id="b">B</h3>
<strong>bitwise operators, <a href="#bitwiseoperators">8</a>, <a href="#operator">31</a></strong><br>
<strong>bytes, <a href="#open">22</a>-<a href="#modes">23</a>, <a href="#pickle">25</a>, <a href="#bytes">28</a>-<a href="#memoryview">29</a></strong> </p>
<h3 id="c">C</h3>
<p><strong>cache, <a href="#lrucache">13</a></strong><br>
<p><strong>cache, <a href="#cache">13</a></strong><br>
<strong>callable, <a href="#callable">17</a></strong><br>
<strong>class, <a href="#type">4</a>, <a href="#class">14</a>-<a href="#inline-1">20</a></strong><br>
<strong>closure, <a href="#closure">12</a>-<a href="#decorator">13</a></strong><br>
Expand All @@ -30,9 +30,9 @@ <h3 id="c">C</h3>
<strong>copy function, <a href="#copy">15</a></strong><br>
<strong>coroutine, <a href="#coroutines">33</a></strong><br>
<strong>counter, <a href="#counter">2</a>, <a href="#generator">4</a>, <a href="#nonlocal">12</a>, <a href="#iterator-1">17</a></strong><br>
<strong>csv, <a href="#csv">26</a>, <a href="#printsacsvspreadsheettotheconsole">34</a>, <a href="#dataframeplotencodedecode">46</a>, <a href="#displaysalinechartoftotalcoronavirusdeathspermilliongroupedbycontinent">47</a></strong><br>
<strong>csv, <a href="#csv">26</a>, <a href="#printsacsvspreadsheettotheconsole">34</a>, <a href="#dataframeencodedecode">46</a>, <a href="#displaysalinechartoftotalcoronavirusdeathspermilliongroupedbycontinent">47</a></strong><br>
<strong>curses module, <a href="#runsaterminalgamewhereyoucontrolanasteriskthatmustavoidnumbers">33</a>, <a href="#consoleapp">34</a></strong><br>
<strong>cython, <a href="#cython">49</a></strong> </p>
<strong>cython, <a href="#typeannotations">15</a>, <a href="#cython">49</a></strong> </p>
<h3 id="d">D</h3>
<p><strong>dataclasses module, <a href="#namedtupleenumdataclass">12</a>, <a href="#dataclass">15</a></strong><br>
<strong>datetime module, <a href="#datetime">8</a>-<a href="#now">9</a></strong><br>
Expand All @@ -43,13 +43,13 @@ <h3 id="d">D</h3>
<h3 id="e">E</h3>
<p><strong>enum module, <a href="#enum">19</a>-<a href="#inline-1">20</a></strong><br>
<strong>enumerate function, <a href="#enumerate">3</a></strong><br>
<strong>excel, <a href="#dataframeplotencodedecode">46</a></strong><br>
<strong>excel, <a href="#dataframeencodedecode">46</a></strong><br>
<strong>exceptions, <a href="#exceptions">20</a>-<a href="#exceptionobject">21</a>, <a href="#exceptions-1">23</a>, <a href="#logging">32</a></strong><br>
<strong>exit function, <a href="#exit">21</a></strong> </p>
<h3 id="f">F</h3>
<p><strong>files, <a href="#print">22</a>-<a href="#memoryview">29</a>, <a href="#runsabasicfileexplorerintheconsole">34</a>, <a href="#dataframeplotencodedecode">46</a></strong><br>
<p><strong>files, <a href="#print">22</a>-<a href="#memoryview">29</a>, <a href="#runsabasicfileexplorerintheconsole">34</a>, <a href="#dataframeencodedecode">46</a></strong><br>
<strong>filter function, <a href="#mapfilterreduce">11</a></strong><br>
<strong>flask library, <a href="#web">36</a></strong><br>
<strong>flask library, <a href="#webapp">36</a></strong><br>
<strong>floats, <a href="#abstractbaseclasses">4</a>, <a href="#floats">6</a>, <a href="#numbers">7</a></strong><br>
<strong>format, <a href="#format">6</a>-<a href="#comparisonofpresentationtypes">7</a></strong><br>
<strong>functools module, <a href="#mapfilterreduce">11</a>, <a href="#partial">12</a>, <a href="#debuggerexample">13</a>, <a href="#sortable">16</a></strong> </p>
Expand All @@ -73,7 +73,7 @@ <h3 id="i">I</h3>
<strong>iterator, <a href="#enumerate">3</a>-<a href="#generator">4</a>, <a href="#comprehensions">11</a>, <a href="#iterator-1">17</a></strong><br>
<strong>itertools module, <a href="#itertools">3</a>, <a href="#combinatorics">8</a></strong> </p>
<h3 id="j">J</h3>
<p><strong>json, <a href="#json">25</a>, <a href="#restrequest">36</a>, <a href="#dataframeplotencodedecode">46</a></strong> </p>
<p><strong>json, <a href="#json">25</a>, <a href="#restrequest">36</a>, <a href="#dataframeencodedecode">46</a></strong> </p>
<h3 id="l">L</h3>
<p><strong>lambda, <a href="#lambda">11</a></strong><br>
<strong>lists, <a href="#list">1</a>-<a href="#list">2</a>, <a href="#abstractbaseclasses">4</a>, <a href="#otheruses">11</a>, <a href="#sequence">18</a>-<a href="#tableofrequiredandautomaticallyavailablespecialmethods">19</a>, <a href="#collectionsandtheirexceptions">21</a></strong><br>
Expand All @@ -82,7 +82,7 @@ <h3 id="l">L</h3>
<h3 id="m">M</h3>
<p><strong>main function, <a href="#main">1</a>, <a href="#basicscripttemplate">49</a></strong><br>
<strong>match statement, <a href="#matchstatement">31</a></strong><br>
<strong>matplotlib library, <a href="#plot">34</a>, <a href="#series">44</a>, <a href="#dataframeplotencodedecode">46</a></strong><br>
<strong>matplotlib library, <a href="#plot">34</a>, <a href="#series">44</a>, <a href="#dataframeencodedecode">46</a></strong><br>
<strong>map function, <a href="#mapfilterreduce">11</a>, <a href="#operator">31</a></strong><br>
<strong>math module, <a href="#numbers">7</a></strong><br>
<strong>memoryviews, <a href="#memoryview">29</a></strong><br>
Expand All @@ -102,7 +102,7 @@ <h3 id="p">P</h3>
<strong>paths, <a href="#paths">23</a>-<a href="#oscommands">24</a>, <a href="#runsabasicfileexplorerintheconsole">34</a></strong><br>
<strong>pickle module, <a href="#pickle">25</a></strong><br>
<strong>pillow library, <a href="#image">39</a>-<a href="#animation">40</a></strong><br>
<strong>plotting, <a href="#plot">34</a>, <a href="#series">44</a>, <a href="#dataframeplotencodedecode">46</a>, <a href="#plotly">47</a>-<a href="#displaysamultiaxislinechartoftotalcoronaviruscasesandchangesinpricesofbitcoindowjonesandgold">48</a></strong><br>
<strong>plotting, <a href="#plot">34</a>, <a href="#series">44</a>, <a href="#dataframeencodedecode">46</a>, <a href="#plotly">47</a>-<a href="#displaysamultiaxislinechartoftotalcoronaviruscasesandchangesinpricesofbitcoindowjonesandgold">48</a></strong><br>
<strong>print function, <a href="#class">14</a>, <a href="#print">22</a></strong><br>
<strong>profiling, <a href="#profiling">36</a>-<a href="#profilingbyline">37</a></strong><br>
<strong>progress bar, <a href="#progressbar">34</a></strong><br>
Expand All @@ -113,26 +113,26 @@ <h3 id="q">Q</h3>
<h3 id="r">R</h3>
<p><strong>random module, <a href="#random">8</a></strong><br>
<strong>ranges, <a href="#range">3</a>, <a href="#abstractbaseclasses">4</a></strong><br>
<strong>recursion, <a href="#lrucache">13</a>, <a href="#builtinexceptions">21</a></strong><br>
<strong>recursion, <a href="#cache">13</a>, <a href="#builtinexceptions">21</a></strong><br>
<strong>reduce function, <a href="#mapfilterreduce">11</a>, <a href="#operator">31</a></strong><br>
<strong>regular expressions, <a href="#regex">5</a>-<a href="#specialsequences">6</a></strong><br>
<strong>requests library, <a href="#scrapespythonsurlandlogofromitswikipediapage">35</a>, <a href="#startstheappinitsownthreadandqueriesitsrestapi">36</a></strong> </p>
<h3 id="s">S</h3>
<p><strong>scope, <a href="#insidefunctiondefinition">10</a>, <a href="#nonlocal">12</a>, <a href="#complexexample">20</a></strong><br>
<strong>scraping, <a href="#scraping">35</a>, <a href="#basicmariobrothersexample">43</a>, <a href="#dataframeplotencodedecode">46</a>, <a href="#displaysalinechartoftotalcoronavirusdeathspermilliongroupedbycontinent">47</a>-<a href="#displaysamultiaxislinechartoftotalcoronaviruscasesandchangesinpricesofbitcoindowjonesandgold">48</a></strong><br>
<strong>scraping, <a href="#scraping">35</a>, <a href="#basicmariobrothersexample">43</a>, <a href="#dataframeencodedecode">46</a>, <a href="#displaysalinechartoftotalcoronavirusdeathspermilliongroupedbycontinent">47</a>-<a href="#displaysamultiaxislinechartoftotalcoronaviruscasesandchangesinpricesofbitcoindowjonesandgold">48</a></strong><br>
<strong>sequence, <a href="#abstractbaseclasses">4</a>, <a href="#sequence">18</a>-<a href="#abcsequence">19</a></strong><br>
<strong>sets, <a href="#set">2</a>, <a href="#abstractbaseclasses">4</a>, <a href="#otheruses">11</a>, <a href="#tableofrequiredandautomaticallyavailablespecialmethods">19</a>, <a href="#collectionsandtheirexceptions">21</a></strong><br>
<strong>shell commands, <a href="#shellcommands">25</a></strong><br>
<strong>sleep function, <a href="#progressbar">34</a></strong><br>
<strong>sortable, <a href="#list">1</a>, <a href="#sortable">16</a></strong><br>
<strong>splat operator, <a href="#splatoperator">10</a>-<a href="#otheruses">11</a>, <a href="#readrowsfromcsvfile">26</a></strong><br>
<strong>sql, <a href="#sqlite">27</a>, <a href="#dataframeplotencodedecode">46</a></strong><br>
<strong>sql, <a href="#sqlite">27</a>, <a href="#dataframeencodedecode">46</a></strong><br>
<strong>statistics, <a href="#statistics">7</a>, <a href="#numpy">37</a>-<a href="#indexing">38</a>, <a href="#pandas">44</a>-<a href="#displaysamultiaxislinechartoftotalcoronaviruscasesandchangesinpricesofbitcoindowjonesandgold">48</a></strong><br>
<strong>strings, <a href="#abstractbaseclasses">4</a>-<a href="#comparisonofpresentationtypes">7</a>, <a href="#class">14</a></strong><br>
<strong>struct module, <a href="#struct">28</a>-<a href="#integertypesuseacapitalletterforunsignedtypeminimumandstandardsizesareinbrackets">29</a></strong><br>
<strong>subprocess module, <a href="#sends11tothebasiccalculatorandcapturesitsoutput">25</a></strong><br>
<strong>super function, <a href="#inheritance">14</a></strong><br>
<strong>sys module, <a href="#lrucache">13</a>, <a href="#exit">21</a>-<a href="#commandlinearguments">22</a></strong> </p>
<strong>sys module, <a href="#cache">13</a>, <a href="#exit">21</a>-<a href="#commandlinearguments">22</a></strong> </p>
<h3 id="t">T</h3>
<p><strong>table, <a href="#csv">26</a>, <a href="#example-1">27</a>, <a href="#table">34</a>, <a href="#numpy">37</a>-<a href="#indexing">38</a>, <a href="#dataframe">45</a>-<a href="#dataframeaggregatetransformmap">46</a></strong><br>
<strong>template, <a href="#format">6</a>, <a href="#dynamicrequest">36</a></strong><br>
Expand All @@ -143,5 +143,5 @@ <h3 id="t">T</h3>
<strong>type annotations, <a href="#typeannotations">15</a>, <a href="#introspection">32</a></strong> </p>
<h3 id="w">W</h3>
<p><strong>wave module, <a href="#audio">40</a>-<a href="#writefloatsamplestowavfile">41</a></strong><br>
<strong>web, <a href="#web">36</a></strong> </p>
<strong>web, <a href="#webapp">36</a></strong> </p>
</div>
2 changes: 1 addition & 1 deletion pdf/index_for_pdf_print.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h3 id="c">C</h3>
<strong>counter, 2, 4, 12, 17</strong><br>
<strong>csv, 26, 34, 46, 47</strong><br>
<strong>curses module, 33, 34</strong><br>
<strong>cython, 49</strong> </p>
<strong>cython, 15, 49</strong> </p>
<h3 id="d">D</h3>
<p><strong>dataclasses module, 12, 15</strong><br>
<strong>datetime module, 8-9</strong><br>
Expand Down
13 changes: 5 additions & 8 deletions web/faq.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<details open><summary><strong>Which Python version is this for?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;Everything should work in the latest Python version, which is 3.12. Every feature that requires version higher than 3.8 has that mentioned in comments or brackets. There are only six such features, four requiring 3.9, and two requiring 3.10.<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;As of 12th March 2024, the only libraries whose latest version requires Python version higher than 3.8 are: numpy, pandas and matplotlib. They all require Python 3.9. This cheatsheet covers pandas library version 2.0 or higher which was released on 3rd April 2023.
&nbsp;&nbsp;&nbsp;&nbsp;Everything should work in the latest Python version, which is 3.12. Every feature that requires version higher than 3.9 has that mentioned in comments or brackets. There are only two such features, both requiring 3.10.<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;As of 12th March 2024, the only libraries whose latest version requires Python version higher than 3.8 are: numpy, pandas and matplotlib. They all require Python 3.9. This cheatsheet covers numpy version 2.0 (or higher) that was released on 16th June, 2024 and pandas version 2.0 (or higher) that was released on 3rd April 2023.
</details><br>

<details open><summary><strong>How to use it?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;This cheatsheet consists of minimal text and short examples so things are easy to find with <code>Ctrl+F</code> / <code>⌘F</code>. If you're on the webpage, searching for <code>'#&lt;name&gt;'</code> will only search for the titles. To get a link to a specific section click the grey hashtag next to the section's title before copying the address. To search for titles in the text editor use <code>^&lt;name&gt;</code> with enabled regular expressions option.<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;I also keep the Python console open at all times to test little snippets of code, to check out the available functions of a module using code completion and above all, to use <code>help(&lt;module/object/function/type/str&gt;)</code> command. If something is still unclear, then I search the Python docs by googling <code>'python docs &lt;module/function&gt;'</code>.<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;Recently I started using the ptpython REPL (Python console). It supports multiline editing, syntax validation, IDE-like autocompletion and syntax highlighting. It can be installed with <code>pip3 install ptpython</code>.
&nbsp;&nbsp;&nbsp;&nbsp;Recently I started using the ptpython REPL (Python console). It supports multiline editing, syntax validation, IDE-like autocompletion and syntax highlighting. It can be installed with <code>pip3 install ptpython</code>. Even more recently I switched to ipython REPL, which is very similar to ptpython only more responsive. It can be installed with <code>pip3 install ipython</code>.
</details><br>

<details open><summary><strong>What does the '&lt;type&gt;' signify?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;It is a placeholder for an object. It needs to be replaced by an expression, literal or a variable that returns/is of that type.
&nbsp;&nbsp;&nbsp;&nbsp;It is a placeholder for an object. It needs to be replaced by an expression, literal or a variable that returns/is of that type. However, if it is located on the left side of an assignment (<code>=</code>) then it signifies what type of object is produced/returned by the expression on the right side of the assignment.
</details><br>

<details open><summary><strong>Why the '&lt;type&gt;' semantics?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;It makes examples much less ambiguous.
</details><br>

<details open><summary><strong>Why are some basics like <code>'&lt;list&gt; = [&lt;el_1&gt;, &lt;el_2&gt;, ...]'</code> and <code>'&lt;el&gt; = &lt;list&gt;[&lt;int&gt;]'</code> missing?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;This cheatsheet is not intended for complete beginners. This way it can save some valuable space. Nonetheless, it tries to be simple enough to be useful for somebody who completed the introductory course. A nice one-page cheatsheet that can help you get started can be found <a href="https://github.com/kickstartcoding/cheatsheets/blob/master/build/topical/python.pdf">here</a>.</details><br>

<details open><summary><strong>What exactly is <code>&lt;el&gt;</code>?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;El is short for element and can be any object, but it usually denotes an object that is an item of a collection.
</details><br>
Expand Down Expand Up @@ -52,4 +49,4 @@

<details open><summary><strong>Why are descriptors not covered?</strong></summary><br>
&nbsp;&nbsp;&nbsp;&nbsp;Because property decorator is sufficient for everyday use.
</details><br>
</details><br>
Binary file added web/image_social_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 27 additions & 4 deletions web/script_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,45 @@ var isMobile = false;
// Device detection:
if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) {
isMobile = true;
isMobile = true;
}

var TOC_SCREEN_WIDTH_CUTOFF = 667
var TOC_EM = '2em'
var TOC_EM_DESKTOP = '1.327em'
var PLOTLY_WIDTH_DESKTOP = 914


function switch_to_mobile_view() {
$(`code:contains(ToC)`).html(TOC_MOBILE).css("line-height", TOC_EM);
const body = document.querySelector("body");
body.style["width"] = `${TOC_SCREEN_WIDTH_CUTOFF+9}px`;
const plotlyDivs = document.querySelectorAll(".plotly-graph-div");
plotlyDivs.forEach((div) => {
div.style["width"] = `${TOC_SCREEN_WIDTH_CUTOFF}px`;
});
}


function switch_to_desktop_view() {
$(`code:contains(ToC)`).html(TOC).css("line-height", TOC_EM_DESKTOP);
const body = document.querySelector("body");
body.style["width"] = "";
const plotlyDivs = document.querySelectorAll(".plotly-graph-div");
plotlyDivs.forEach((div) => {
div.style["width"] = `${PLOTLY_WIDTH_DESKTOP}px`;
});
}

if (isMobile && window.screen.width < TOC_SCREEN_WIDTH_CUTOFF) {
$(`code:contains(ToC)`).html(TOC_MOBILE).css("line-height", TOC_EM);
switch_to_mobile_view()
}

function updateToc() {
if (isMobile && window.screen.width < TOC_SCREEN_WIDTH_CUTOFF) {
$(`code:contains(ToC)`).html(TOC_MOBILE).css("line-height", TOC_EM);
switch_to_mobile_view();
} else {
$(`code:contains(ToC)`).html(TOC).css("line-height", TOC_EM_DESKTOP);
switch_to_desktop_view();
}
}
window.addEventListener("orientationchange", updateToc, false);
Expand Down
Loading

0 comments on commit 8fcaf23

Please sign in to comment.