|
1729 | 1729 | </code></pre></div> |
1730 | 1730 |
|
1731 | 1731 |
|
1732 | | -<pre><code class="python language-python hljs"><num> = <mview>[<index>] <span class="hljs-comment"># Returns int in range from 0 to 255.</span> |
1733 | | -<mview> = <mview>[<slice>] <span class="hljs-comment"># Returns bytes even if it has only one element.</span> |
1734 | | -<file>.write(<mview>) |
1735 | | -</code></pre> |
1736 | | -<pre><code class="python language-python hljs"><bytes> = <bytes>.join(<coll_of_mviews>) <span class="hljs-comment"># Joins elements using bytes object as separator.</span> |
1737 | | -<bytes> = bytes(<mview>) <span class="hljs-comment"># Or: <mview>.tobytes() </span> |
1738 | | -<span class="hljs-string">'<hex>'</span> = <mview>.hex() |
1739 | | -<list> = list(<mview>) <span class="hljs-comment"># Returns numbers.</span> |
1740 | | -<str> = str(<mview>, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Or: <bytes>.decode('utf-8')</span> |
1741 | | -<int> = int.from_bytes(<mview>, byteorder=<span class="hljs-string">'big|little'</span>, signed=<span class="hljs-keyword">False</span>) |
1742 | | -<span class="hljs-string">'<hex>'</span> = <bytes>.hex() |
1743 | | -</code></pre> |
1744 | 1732 | <div><h2 id="deque"><a href="#deque" name="deque">#</a>Deque</h2><p><strong>A thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> deque |
1745 | 1733 | <deque> = deque(<collection>, maxlen=<span class="hljs-keyword">None</span>) |
1746 | 1734 | </code></pre></div> |
|
1950 | 1938 | <span class="hljs-keyword">from</span> matplotlib <span class="hljs-keyword">import</span> pyplot |
1951 | 1939 | </code></pre></div> |
1952 | 1940 |
|
1953 | | -<pre><code class="python language-python hljs">pyplot.plot(<y_data>) |
1954 | | -pyplot.plot(<x_data>, <y_data>) |
1955 | | -pyplot.plot(..., label=<str>) <span class="hljs-comment"># Use `pyplot.legend()` to add legend.</span> |
1956 | | -pyplot.savefig(<filename>) <span class="hljs-comment"># Saves figure.</span> |
1957 | | -pyplot.show() <span class="hljs-comment"># Displays figure.</span> |
1958 | | -pyplot.clf() <span class="hljs-comment"># Clears figure.</span> |
| 1941 | +<pre><code class="python language-python hljs">pyplot.plot(<y_data>) <span class="hljs-comment"># X values start from 0.</span> |
| 1942 | +pyplot.plot(<x_data>, <y_data>) <span class="hljs-comment"># Add `label=<str>` for legend.</span> |
| 1943 | +</code></pre> |
| 1944 | +<pre><code class="python language-python hljs">pyplot.legend() <span class="hljs-comment"># Adds a legend.</span> |
| 1945 | +pyplot.savefig(<filename>) <span class="hljs-comment"># Saves figure.</span> |
| 1946 | +pyplot.show() <span class="hljs-comment"># Displays figure.</span> |
| 1947 | +pyplot.clf() <span class="hljs-comment"># Clears figure.</span> |
1959 | 1948 | </code></pre> |
1960 | 1949 | <div><h2 id="table"><a href="#table" name="table">#</a>Table</h2><div><h4 id="printsacsvfileasanasciitable">Prints a CSV file as an ASCII table:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install tabulate</span> |
1961 | 1950 | <span class="hljs-keyword">import</span> csv, tabulate |
|
0 commit comments