<li><strong>Module <ahref="#operator">operator</a> provides functions itemgetter() and mul() that offer the same functionality as <ahref="#lambda">lambda</a> expressions above.</strong></li>
</ul>
<pre><codeclass="python language-python hljs"><int> = <list>.count(<el>) <spanclass="hljs-comment"># Returns number of occurrences. Also works on strings.</span>
index = <list>.index(<el>) <spanclass="hljs-comment"># Returns index of first occurrence or raises ValueError.</span>
<list>.insert(index, <el>) <spanclass="hljs-comment"># Inserts item at index and moves the rest to the right.</span>
<el> = <list>.pop([index]) <spanclass="hljs-comment"># Removes and returns item at index or from the end.</span>
<list>.remove(<el>) <spanclass="hljs-comment"># Removes first occurrence of item or raises ValueError.</span>
<int> = <list>.index(<el>) <spanclass="hljs-comment"># Returns index of the first occurrence or raises ValueError.</span>
<list>.insert(<int>, <el>) <spanclass="hljs-comment"># Inserts item at index and moves the rest to the right.</span>
<el> = <list>.pop([<int>]) <spanclass="hljs-comment"># Removes and returns item at index or from the end.</span>
<list>.remove(<el>) <spanclass="hljs-comment"># Removes first occurrence of the item or raises ValueError.</span>
<list>.clear() <spanclass="hljs-comment"># Removes all items. Also works on dictionary and set.</span>
</code></pre>
<div><h2id="dictionary"><ahref="#dictionary"name="dictionary">#</a>Dictionary</h2><pre><codeclass="python language-python hljs"><view> = <dict>.keys() <spanclass="hljs-comment"># Coll. of keys that reflects changes.</span>
<pre><codeclass="python language-python hljs"><list> = <str>.split() <spanclass="hljs-comment"># Splits on one or more whitespace characters.</span>
<list> = <str>.split(sep=<spanclass="hljs-keyword">None</span>, maxsplit=<spanclass="hljs-number">-1</span>) <spanclass="hljs-comment"># Splits on 'sep' str at most 'maxsplit' times.</span>
<list> = <str>.splitlines(keepends=<spanclass="hljs-keyword">False</span>) <spanclass="hljs-comment"># Splits on \n,\r,\r\n. Keeps them if 'keepends'.</span>
<str> = <str>.join(<coll_of_strings>) <spanclass="hljs-comment"># Joins elements using string as separator.</span>
<str> = <str>.join(<coll_of_strings>) <spanclass="hljs-comment"># Joins elements using string as a separator.</span>
</code></pre>
<pre><codeclass="python language-python hljs"><bool> = <sub_str><spanclass="hljs-keyword">in</span><str><spanclass="hljs-comment"># Checks if string contains a substring.</span>
<bool> = <str>.startswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
<bool> = <str>.endswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
<int> = <str>.find(<sub_str>) <spanclass="hljs-comment"># Returns start index of first match or -1.</span>
<int> = <str>.find(<sub_str>) <spanclass="hljs-comment"># Returns start index of the first match or -1.</span>
<int> = <str>.index(<sub_str>) <spanclass="hljs-comment"># Same but raises ValueError if missing.</span>
</code></pre>
<pre><codeclass="python language-python hljs"><str> = <str>.replace(old, new [, count]) <spanclass="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
<div><h2id="scraping"><ahref="#scraping"name="scraping">#</a>Scraping</h2><div><h4id="scrapespythonsurlversionnumberandlogofromitswikipediapage">Scrapes Python's URL, version number and logo from its Wikipedia page:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install requests beautifulsoup4</span>
link = table.find(<spanclass="hljs-string">'th'</span>, text=<spanclass="hljs-string">'Website'</span>).next_sibling.a[<spanclass="hljs-string">'href'</span>]
ver = table.find(<spanclass="hljs-string">'th'</span>, text=<spanclass="hljs-string">'Stable release'</span>).next_sibling.strings.__next__()
xxxxxxxxxx