@ -54,7 +54,7 @@
< body >
< header >
< aside > August 2 , 2023< / aside >
< aside > August 3 , 2023< / aside >
< a href = "https://gto76.github.io" rel = "author" > Jure Šorn< / a >
< / header >
@ -96,20 +96,20 @@
< div > < h2 id = "main" > < a href = "#main" name = "main" > #< / a > Main< / h2 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > if< / span > __name__ == < span class = "hljs-string" > '__main__'< / span > : < span class = "hljs-comment" > # Runs main() if file wasn't imported.< / span >
< div > < h2 id = "main" > < a href = "#main" name = "main" > #< / a > Main< / h2 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > if< / span > __name__ == < span class = "hljs-string" > '__main__'< / span > : < span class = "hljs-comment" > # Runs main() if file wasn't imported.< / span >
main()
< / code > < / pre > < / div >
< div > < h2 id = "list" > < a href = "#list" name = "list" > #< / a > List< / h2 > < pre > < code class = "python language-python hljs" > < list> = < list> [< slice> ] < span class = "hljs-comment" > # Or: < list> [from_inclusive : to_exclusive : ±step]< / span >
< div > < h2 id = "list" > < a href = "#list" name = "list" > #< / a > List< / h2 > < pre > < code class = "python language-python hljs" > < list> = < list> [< slice> ] < span class = "hljs-comment" > # Or: < list> [from_inclusive : to_exclusive : ±step]< / span >
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < list> .append(< el> ) < span class = "hljs-comment" > # Or: < list> += [< el> ]< / span >
< list> .extend(< collection> ) < span class = "hljs-comment" > # Or: < list> += < collection> < / span >
< pre > < code class = "python language-python hljs" > < list> .append(< el> ) < span class = "hljs-comment" > # Or: < list> += [< el> ]< / span >
< list> .extend(< collection> ) < span class = "hljs-comment" > # Or: < list> += < collection> < / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < list> .sort() < span class = "hljs-comment" > # Sorts in ascending order.< / span >
< list> .reverse() < span class = "hljs-comment" > # Reverses the list in-place.< / span >
< list> = sorted(< collection> ) < span class = "hljs-comment" > # Returns a new sorted list.< / span >
< iter> = reversed(< list> ) < span class = "hljs-comment" > # Returns reversed iterator.< / span >
< pre > < code class = "python language-python hljs" > < list> .sort() < span class = "hljs-comment" > # Sorts in ascending order.< / span >
< list> .reverse() < span class = "hljs-comment" > # Reverses the list in-place.< / span >
< list> = sorted(< collection> ) < span class = "hljs-comment" > # Returns a new sorted list.< / span >
< iter> = reversed(< list> ) < span class = "hljs-comment" > # Returns reversed iterator.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > sum_of_elements = sum(< collection> )
elementwise_sum = [sum(pair) < span class = "hljs-keyword" > for< / span > pair < span class = "hljs-keyword" > in< / span > zip(list_a, list_b)]
@ -123,12 +123,12 @@ list_of_chars = list(<str>)
< li > < strong > For details about sorted(), min() and max() see < a href = "#sortable" > sortable< / a > .< / strong > < / li >
< li > < strong > Module < a href = "#operator" > operator< / a > provides functions itemgetter() and mul() that offer the same functionality as < a href = "#lambda" > lambda< / a > expressions above.< / strong > < / li >
< / ul >
< pre > < code class = "python language-python hljs" > < list> .insert(< int> , < el> ) < span class = "hljs-comment" > # Inserts item at index and moves the rest to the right.< / span >
< el> = < list> .pop([< int> ]) < span class = "hljs-comment" > # Removes and returns item at index or from the end.< / span >
< int> = < list> .count(< el> ) < span class = "hljs-comment" > # Returns number of occurrences. Also works on strings.< / span >
< int> = < list> .index(< el> ) < span class = "hljs-comment" > # Returns index of the first occurrence or raises ValueError.< / span >
< list> .remove(< el> ) < span class = "hljs-comment" > # Removes first occurrence of the item or raises ValueError.< / span >
< list> .clear() < span class = "hljs-comment" > # Removes all items. Also works on dictionary and set.< / span >
< pre > < code class = "python language-python hljs" > < list> .insert(< int> , < el> ) < span class = "hljs-comment" > # Inserts item at index and moves the rest to the right.< / span >
< el> = < list> .pop([< int> ]) < span class = "hljs-comment" > # Removes and returns item at index or from the end.< / span >
< int> = < list> .count(< el> ) < span class = "hljs-comment" > # Returns number of occurrences. Also works on strings.< / span >
< int> = < list> .index(< el> ) < span class = "hljs-comment" > # Returns index of the first occurrence or raises ValueError.< / span >
< list> .remove(< el> ) < span class = "hljs-comment" > # Removes first occurrence of the item or raises ValueError.< / span >
< list> .clear() < span class = "hljs-comment" > # Removes all items. Also works on dictionary and set.< / span >
< / code > < / pre >
< div > < h2 id = "dictionary" > < a href = "#dictionary" name = "dictionary" > #< / a > Dictionary< / h2 > < pre > < code class = "python language-python hljs" > < view> = < dict> .keys() < span class = "hljs-comment" > # Coll. of keys that reflects changes.< / span >
< view> = < dict> .values() < span class = "hljs-comment" > # Coll. of values that reflects changes.< / span >
@ -182,9 +182,9 @@ Counter({<span class="hljs-string">'blue'</span>: <span class="hljs-number">3</s
< / code > < / pre > < / div >
< div > < h2 id = "tuple" > < a href = "#tuple" name = "tuple" > #< / a > Tuple< / h2 > < p > < strong > Tuple is an immutable and hashable list.< / strong > < / p > < pre > < code class = "python language-python hljs" > < tuple> = () < span class = "hljs-comment" > # Empty tuple.< / span >
< tuple> = (< el> ,) < span class = "hljs-comment" > # Or: < el> ,< / span >
< tuple> = (< el_1> , < el_2> [, ...]) < span class = "hljs-comment" > # Or: < el_1> , < el_2> [, ...]< / span >
< div > < h2 id = "tuple" > < a href = "#tuple" name = "tuple" > #< / a > Tuple< / h2 > < p > < strong > Tuple is an immutable and hashable list.< / strong > < / p > < pre > < code class = "python language-python hljs" > < tuple> = () < span class = "hljs-comment" > # Empty tuple.< / span >
< tuple> = (< el> ,) < span class = "hljs-comment" > # Or: < el> ,< / span >
< tuple> = (< el_1> , < el_2> [, ...]) < span class = "hljs-comment" > # Or: < el_1> , < el_2> [, ...]< / span >
< / code > < / pre > < / div >
@ -201,9 +201,9 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
< / code > < / pre > < / div >
< div > < h2 id = "range" > < a href = "#range" name = "range" > #< / a > Range< / h2 > < p > < strong > Immutable and hashable sequence of integers.< / strong > < / p > < pre > < code class = "python language-python hljs" > < range> = range(stop) < span class = "hljs-comment" > # range(to_exclusive)< / span >
< range> = range(start, stop) < span class = "hljs-comment" > # range(from_inclusive, to_exclusive)< / span >
< range> = range(start, stop, ±step) < span class = "hljs-comment" > # range(from_inclusive, to_exclusive, ±step_size)< / span >
< div > < h2 id = "range" > < a href = "#range" name = "range" > #< / a > Range< / h2 > < p > < strong > Immutable and hashable sequence of integers.< / strong > < / p > < pre > < code class = "python language-python hljs" > < range> = range(stop) < span class = "hljs-comment" > # range(to_exclusive)< / span >
< range> = range(start, stop) < span class = "hljs-comment" > # range(from_inclusive, to_exclusive)< / span >
< range> = range(start, stop, ±step) < span class = "hljs-comment" > # range(from_inclusive, to_exclusive, ±step_size)< / span >
< / code > < / pre > < / div >
@ -214,24 +214,24 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
...
< / code > < / pre > < / div >
< div > < h2 id = "iterator" > < a href = "#iterator" name = "iterator" > #< / a > Iterator< / h2 > < pre > < code class = "python language-python hljs" > < iter> = iter(< collection> ) < span class = "hljs-comment" > # `iter(< iter> )` returns unmodified iterator.< / span >
< iter> = iter(< function> , to_exclusive) < span class = "hljs-comment" > # A sequence of return values until 'to_exclusive'.< / span >
< el> = next(< iter> [, default]) < span class = "hljs-comment" > # Raises StopIteration or returns 'default' on end.< / span >
< list> = list(< iter> ) < span class = "hljs-comment" > # Returns a list of iterator's remaining elements.< / span >
< div > < h2 id = "iterator" > < a href = "#iterator" name = "iterator" > #< / a > Iterator< / h2 > < pre > < code class = "python language-python hljs" > < iter> = iter(< collection> ) < span class = "hljs-comment" > # `iter(< iter> )` returns unmodified iterator.< / span >
< iter> = iter(< function> , to_exclusive) < span class = "hljs-comment" > # A sequence of return values until 'to_exclusive'.< / span >
< el> = next(< iter> [, default]) < span class = "hljs-comment" > # Raises StopIteration or returns 'default' on end.< / span >
< list> = list(< iter> ) < span class = "hljs-comment" > # Returns a list of iterator's remaining elements.< / span >
< / code > < / pre > < / div >
< div > < h3 id = "itertools" > Itertools< / h3 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > import< / span > itertools < span class = "hljs-keyword" > as< / span > it
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < iter> = it.count(start=< span class = "hljs-number" > 0< / span > , step=< span class = "hljs-number" > 1< / span > ) < span class = "hljs-comment" > # Returns updated value endlessly. Accepts floats.< / span >
< iter> = it.repeat(< el> [, times]) < span class = "hljs-comment" > # Returns element endlessly or 'times' times.< / span >
< iter> = it.cycle(< collection> ) < span class = "hljs-comment" > # Repeats the sequence endlessly.< / span >
< pre > < code class = "python language-python hljs" > < iter> = it.count(start=< span class = "hljs-number" > 0< / span > , step=< span class = "hljs-number" > 1< / span > ) < span class = "hljs-comment" > # Returns updated value endlessly. Accepts floats.< / span >
< iter> = it.repeat(< el> [, times]) < span class = "hljs-comment" > # Returns element endlessly or 'times' times.< / span >
< iter> = it.cycle(< collection> ) < span class = "hljs-comment" > # Repeats the sequence endlessly.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < iter> = it.chain(< coll> , < coll> [, ...]) < span class = "hljs-comment" > # Empties collections in order (figuratively).< / span >
< iter> = it.chain.from_iterable(< coll> ) < span class = "hljs-comment" > # Empties collections inside a collection in order.< / span >
< pre > < code class = "python language-python hljs" > < iter> = it.chain(< coll> , < coll> [, ...]) < span class = "hljs-comment" > # Empties collections in order (figuratively).< / span >
< iter> = it.chain.from_iterable(< coll> ) < span class = "hljs-comment" > # Empties collections inside a collection in order.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < iter> = it.islice(< coll> , to_exclusive) < span class = "hljs-comment" > # Only returns first 'to_exclusive' elements.< / span >
< iter> = it.islice(< coll> , from_inc, …) < span class = "hljs-comment" > # `to_exclusive, +step_size`. Indices can be None.< / span >
< pre > < code class = "python language-python hljs" > < iter> = it.islice(< coll> , to_exclusive) < span class = "hljs-comment" > # Only returns first 'to_exclusive' elements.< / span >
< iter> = it.islice(< coll> , from_inc, …) < span class = "hljs-comment" > # `to_exclusive, +step_size`. Indices can be None.< / span >
< / code > < / pre >
< div > < h2 id = "generator" > < a href = "#generator" name = "generator" > #< / a > Generator< / h2 > < ul >
< li > < strong > Any function that contains a yield statement returns a generator.< / strong > < / li >
@ -2930,7 +2930,7 @@ $ deactivate <span class="hljs-comment"># Deactivates virtual e
< footer >
< aside > August 2 , 2023< / aside >
< aside > August 3 , 2023< / aside >
< a href = "https://gto76.github.io" rel = "author" > Jure Šorn< / a >
< / footer >