You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<div><h1id="comprehensivepythoncheatsheet">Comprehensive Python Cheatsheet</h1><pclass="banner"><sup><ahref="https://raw.githubusercontent.com/gto76/python-cheatsheet/main/README.md">Download text file</a>, <ahref="https://github.com/gto76/python-cheatsheet">Fork me on GitHub</a>, <ahref="https://github.com/gto76/python-cheatsheet/wiki/Frequently-Asked-Questions">Check out FAQ</a> or <ahref="index.html?theme=dark3">Switch to dark theme</a>.
63
+
<divclass="pagebreak"></div>
64
+
<div><h1id="comprehensivepythoncheatsheet">Comprehensive Python Cheatsheet</h1><pclass="banner"><sup><ahref="https://raw.githubusercontent.com/gto76/python-cheatsheet/main/README.md">Download text file</a>, <ahref="https://github.com/gto76/python-cheatsheet">Fork me on GitHub</a>, <ahref="https://github.com/gto76/python-cheatsheet/wiki/Frequently-Asked-Questions">Check out FAQ</a> or <ahref="index.html?theme=dark3">Switch to dark theme</a>.
// Changes the banner image and link-to-theme if "theme=dark" is in query string
66
67
// or if browser prefers dark mode and theme is not explicitly set.
@@ -340,7 +341,7 @@
340
341
341
342
<div><h2id="regex"><ahref="#regex" name="regex">#</a>Regex</h2><p><strong>Functions for regular expression matching.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> re
342
343
<str> = re.sub(<spanclass="hljs-string">r'<regex>'</span>, new, text, count=<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Substitutes all occurrences with 'new'.</span>
343
-
<list> = re.findall(<spanclass="hljs-string">r'<regex>'</span>, text) <spanclass="hljs-comment"># Returns all occurrences as strings.</span>
344
+
<list> = re.findall(<spanclass="hljs-string">r'<regex>'</span>, text) <spanclass="hljs-comment"># Returns all occurrences of the pattern.</span>
344
345
<list> = re.split(<spanclass="hljs-string">r'<regex>'</span>, text, maxsplit=<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Add brackets around regex to keep matches.</span>
345
346
<Match> = re.search(<spanclass="hljs-string">r'<regex>'</span>, text) <spanclass="hljs-comment"># First occurrence of the pattern or None.</span>
346
347
<Match> = re.match(<spanclass="hljs-string">r'<regex>'</span>, text) <spanclass="hljs-comment"># Searches only at the beginning of the text.</span>
@@ -373,7 +374,7 @@
373
374
<li><strong>Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).</strong></li>
374
375
</ul>
375
376
<div><h2id="format"><ahref="#format" name="format">#</a>Format</h2><pre><codeclass="python hljs"><str> = <spanclass="hljs-string">f'<spanclass="hljs-subst">{<el_1>}</span>, <spanclass="hljs-subst">{<el_2>}</span>'</span><spanclass="hljs-comment"># Curly brackets can also contain expressions.</span>
<div><h2id="function"><ahref="#function" name="function">#</a>Function</h2><p><strong>Independent block of code that returns a value when called.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-function"><spanclass="hljs-keyword">def</span> <<spanclass="hljs-title">func_name</span>><spanclass="hljs-params">(<nondefault_args>)</span>:</span> ... <spanclass="hljs-comment"># E.g. `def func(x, y): ...`.</span>
@@ -1568,7 +1568,6 @@
1568
1568
<div><h3id="writerowstocsvfile">Write Rows to CSV File</h3><pre><codeclass="python language-python hljs"><spanclass="hljs-function"><spanclass="hljs-keyword">def</span><spanclass="hljs-title">write_to_csv_file</span><spanclass="hljs-params">(filename, rows, mode=<spanclass="hljs-string">'w'</span>, **csv_params)</span>:</span>
<div><h2id="sqlite"><ahref="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>A server-less database engine that stores each database into its own file.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> sqlite3
<el> = <Queue>.get_nowait() <spanclass="hljs-comment"># Raises queue.Empty exception if empty.</span>
1889
1888
</code></pre></div>
1890
1889
1891
-
<div><h3id="threadpoolexecutor">Thread Pool Executor</h3><pre><codeclass="python language-python hljs"><Exec> = ThreadPoolExecutor(max_workers=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Or: `with ThreadPoolExecutor() as <name>: ...`</span>
1890
+
<div><h3id="threadpoolexecutor">Thread Pool Executor</h3><pre><codeclass="python language-python hljs"><Exec> = ThreadPoolExecutor(max_workers=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Also `with ThreadPoolExecutor() as <name>: …`.</span>
<view> = <array>.transpose() <spanclass="hljs-comment"># Flips the table over its diagonal.</span>
2195
2193
</code></pre>
2196
2194
<pre><codeclass="python language-python hljs"><array> = np.copy/abs/sqrt/log/int64(<array>) <spanclass="hljs-comment"># Returns new array of the same shape.</span>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'fill=<color>'</span></code> to set the primary color.</strong></li>
2324
2322
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'width=<int>'</span></code> to set the width of lines or contours.</strong></li>
2325
2323
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'outline=<color>'</span></code> to set the color of the contours.</strong></li>
2326
-
<li><strong>Color can be an int, tuple, <codeclass="python hljs"><spanclass="hljs-string">'#rrggbb[aa]'</span></code> or a color name.</strong></li>
2324
+
<li><strong>Color can be an int, tuple, <codeclass="python hljs"><spanclass="hljs-string">'#rrggbb[aa]'</span></code>string or a color name.</strong></li>
2327
2325
</ul>
2328
2326
<div><h2id="animation"><ahref="#animation" name="animation">#</a>Animation</h2><div><h4id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install imageio</span>
<Fig> = px.histogram(<DF>, x=col_keys, y=col_key) <spanclass="hljs-comment"># Also color, nbins. All are optional.</span>
2799
2797
</code></pre>
2800
-
<div><h4id="displaysalinechartoftotalcoronavirusdeathspermilliongroupedbycontinent">Displays a line chart of total coronavirus deaths per million grouped by continent:</h4><p></p><divid="2a950764-39fc-416d-97fe-0a6226a3095f" class="plotly-graph-div" style="height:312px; width:914px;"></div><pre><codeclass="python language-python hljs">covid = pd.read_csv(<spanclass="hljs-string">'https://raw.githubusercontent.com/owid/covid-19-data/8dde8ca49b'</span>
2798
+
<div><h4id="displaysalinechartoftotalcovid19deathspermilliongroupedbycontinent">Displays a line chart of total COVID-19 deaths per million grouped by continent:</h4><p></p><divid="2a950764-39fc-416d-97fe-0a6226a3095f" class="plotly-graph-div" style="height:312px; width:914px;"></div><pre><codeclass="python language-python hljs">covid = pd.read_csv(<spanclass="hljs-string">'https://raw.githubusercontent.com/owid/covid-19-data/8dde8ca49b'</span>
<div><h4id="displaysamultiaxislinechartoftotalcoronaviruscasesandchangesinpricesofbitcoindowjonesandgold">Displays a multi-axis line chart of total coronavirus cases and changes in prices of Bitcoin, Dow Jones and gold:</h4><p></p><divid="e23ccacc-a456-478b-b467-7282a2165921" class="plotly-graph-div" style="height:285px; width:935px;"></div><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install pandas lxml selenium plotly</span>
2813
+
<div><h4id="displaysamultiaxislinechartoftotalcovid19casesandchangesinpricesofbitcoindowjonesandgold">Displays a multi-axis line chart of total COVID-19 cases and changes in prices of Bitcoin, Dow Jones and gold:</h4><p></p><divid="e23ccacc-a456-478b-b467-7282a2165921" class="plotly-graph-div" style="height:285px; width:935px;"></div><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install pandas lxml selenium plotly</span>
2816
2814
<spanclass="hljs-keyword">import</span> pandas <spanclass="hljs-keyword">as</span> pd, selenium.webdriver, io, plotly.graph_objects <spanclass="hljs-keyword">as</span> go
0 commit comments