From 354421459d29da006ce535dd52ed64d25a4bd9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 7 May 2019 21:00:43 +0200 Subject: [PATCH 1/9] Numbers --- README.md | 1 + index.html | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 64b14ae..ea92f9f 100644 --- a/README.md +++ b/README.md @@ -412,6 +412,7 @@ Numbers = float() = complex(real=0, imag=0) # Or: + j ``` +* **`'int()'` and `'float()'` raise ValueError on malformed string.** ### Basic Functions ```python diff --git a/index.html b/index.html index e639f46..2ff50a7 100644 --- a/index.html +++ b/index.html @@ -484,6 +484,9 @@ Point(x=1, y=2 <float> = float(<int/str/bool>) <complex> = complex(real=0, imag=0) # Or: <real> + <real>j +
    +
  • 'int()' and 'float()' raise ValueError on malformed string.
  • +

Basic Functions

<num>  = pow(<num>, <num>)           # Or: <num> ** <num>
 <real> = abs(<num>)

From 30d07cd0e155415b8a3dea52b79e24d2ca043633 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 12:09:40 +0200
Subject: [PATCH 2/9] Numbers

---
 README.md  | 2 +-
 index.html | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index ea92f9f..f7ac43d 100644
--- a/README.md
+++ b/README.md
@@ -412,7 +412,7 @@ Numbers
    = float()
  = complex(real=0, imag=0)  # Or:  + j
 ```
-* **`'int()'` and `'float()'` raise ValueError on malformed string.**
+* **`'int()'` and `'float()'` raise ValueError on malformed strings.**
 
 ### Basic Functions
 ```python
diff --git a/index.html b/index.html
index 2ff50a7..39ede9c 100644
--- a/index.html
+++ b/index.html
@@ -485,7 +485,7 @@ Point(x=1, y=2
 <complex> = complex(real=0, imag=0)  # Or: <real> + <real>j
 
    -
  • 'int()' and 'float()' raise ValueError on malformed string.
  • +
  • 'int(<str>)' and 'float(<str>)' raise ValueError on malformed strings.

Basic Functions

<num>  = pow(<num>, <num>)           # Or: <num> ** <num>

From c2b3a1a761083cabb568f841f5bc53852a4f7ea5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 18:26:25 +0200
Subject: [PATCH 3/9] ABC

---
 README.md       | 38 ++++++++++++++++++++++++++++++--------
 index.html      | 36 +++++++++++++++++++++++++++---------
 parse.js        | 43 ++++++++++++++++++++++++++++++++++++++++++-
 web/script_2.js | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+), 18 deletions(-)

diff --git a/README.md b/README.md
index f7ac43d..1bd66b9 100644
--- a/README.md
+++ b/README.md
@@ -249,15 +249,36 @@ from types import FunctionType, MethodType, LambdaType, GeneratorType
 **An abstract base class introduces virtual subclasses, that don’t inherit from it but are still recognized by isinstance() and issubclass().**
 
 ```python
-from numbers import Integral, Rational, Real, Complex, Number
-from collections.abc import Sequence, Collection, Iterable
+>>> from collections.abc import Sequence, Collection, Iterable
+>>> isinstance([1, 2, 3], Iterable)
+True
+```
+
+```text
++------------------+----------+------------+----------+
+|                  | Sequence | Collection | Iterable |
++------------------+----------+------------+----------+
+| list, range, str |   yes    |    yes     |   yes    |
+| dict, set        |          |    yes     |   yes    |
+| iter             |          |            |   yes    |
++------------------+----------+------------+----------+
 ```
 
 ```python
+>>> from numbers import Integral, Rational, Real, Complex, Number
 >>> isinstance(123, Number)
 True
->>> isinstance([1, 2, 3], Iterable)
-True
+```
+
+```text
++--------------------+----------+----------+------+---------+--------+
+|                    | Integral | Rational | Real | Complex | Number |
++--------------------+----------+----------+------+---------+--------+
+| int                |   yes    |   yes    | yes  |   yes   |  yes   |
+| fractions.Fraction |          |   yes    | yes  |   yes   |  yes   |
+| float              |          |          | yes  |   yes   |  yes   |
+| complex            |          |          |      |   yes   |  yes   |
++--------------------+----------+----------+------+---------+--------+
 ```
 
 
@@ -408,15 +429,16 @@ Format
 Numbers
 -------
 ```python
-     = int()    # Or: math.floor()
-   = float()
- = complex(real=0, imag=0)  # Or:  + j
+      = int()    # Or: math.floor()
+    = float()
+  = complex(real=0, imag=0)  # Or:  + j
+ = fractions.Fraction(numerator=0, denominator=1)
 ```
 * **`'int()'` and `'float()'` raise ValueError on malformed strings.**
 
 ### Basic Functions
 ```python
-  = pow(, )           # Or:  ** 
+  = pow(, )            # Or:  ** 
  = abs()
   = round()
  = round(, ±ndigits)
diff --git a/index.html b/index.html
index 39ede9c..fea4acc 100644
--- a/index.html
+++ b/index.html
@@ -365,14 +365,31 @@ Point(x=1, y=2
 

ABC

An abstract base class introduces virtual subclasses, that don’t inherit from it but are still recognized by isinstance() and issubclass().

-
from numbers import Integral, Rational, Real, Complex, Number
-from collections.abc import Sequence, Collection, Iterable
-
-
>>> isinstance(123, Number)
-True
+
>>> from collections.abc import Sequence, Collection, Iterable
 >>> isinstance([1, 2, 3], Iterable)
 True
 
+
┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┓
+┃                  │ Sequence │ Collection │ Iterable ┃
+┠──────────────────┼──────────┼────────────┼──────────┨
+┃ list, range, str │    ✓     │     ✓      │    ✓     ┃
+┃ dict, set        │          │     ✓      │    ✓     ┃
+┃ iter             │          │            │    ✓     ┃
+┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┛
+
+
>>> from numbers import Integral, Rational, Real, Complex, Number
+>>> isinstance(123, Number)
+True
+
+
┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┯━━━━━━━━━┯━━━━━━━━┓
+┃                    │ Integral │ Rational │ Real │ Complex │ Number ┃
+┠────────────────────┼──────────┼──────────┼──────┼─────────┼────────┨
+┃ int                │    ✓     │    ✓     │  ✓   │    ✓    │   ✓    ┃
+┃ fractions.Fraction │          │    ✓     │  ✓   │    ✓    │   ✓    ┃
+┃ float              │          │          │  ✓   │    ✓    │   ✓    ┃
+┃ complex            │          │          │      │    ✓    │   ✓    ┃
+┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┷━━━━━━━━━┷━━━━━━━━┛
+

#String

<str>  = <str>.strip()                       # Strips all whitespace characters from both ends.
 <str>  = <str>.strip('<chars>')              # Strips all passed characters from both ends.
@@ -480,15 +497,16 @@ Point(x=1, y=2
 {90:b}           # '1011010'
 

#Numbers

-
<int>     = int(<float/str/bool>)    # Or: math.floor(<float>)
-<float>   = float(<int/str/bool>)
-<complex> = complex(real=0, imag=0)  # Or: <real> + <real>j
+
<int>      = int(<float/str/bool>)    # Or: math.floor(<float>)
+<float>    = float(<int/str/bool>)
+<complex>  = complex(real=0, imag=0)  # Or: <real> + <real>j
+<Fraction> = fractions.Fraction(numerator=0, denominator=1)
 
  • 'int(<str>)' and 'float(<str>)' raise ValueError on malformed strings.

Basic Functions

-
<num>  = pow(<num>, <num>)           # Or: <num> ** <num>
+
<num>  = pow(<num>, <num>)            # Or: <num> ** <num>
 <real> = abs(<num>)
 <int>  = round(<real>)
 <real> = round(<real>, ±ndigits)
diff --git a/parse.js b/parse.js
index cb1e860..f9ea021 100755
--- a/parse.js
+++ b/parse.js
@@ -74,6 +74,44 @@ const DIAGRAM_2_B =
   '┃   str   │             ┃\n' +
   '┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
 
+const DIAGRAM_3_A =
+  '+------------------+----------+------------+----------+\n' +
+  '|                  | Sequence | Collection | Iterable |\n' +
+  '+------------------+----------+------------+----------+\n' +
+  '| list, range, str |   yes    |    yes     |   yes    |\n' +
+  '| dict, set        |          |    yes     |   yes    |\n' +
+  '| iter             |          |            |   yes    |\n' +
+  '+------------------+----------+------------+----------+\n';
+
+const DIAGRAM_3_B =
+  '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┓\n' +
+  '┃                  │ Sequence │ Collection │ Iterable ┃\n' +
+  '┠──────────────────┼──────────┼────────────┼──────────┨\n' +
+  '┃ list, range, str │    ✓     │     ✓      │    ✓     ┃\n' +
+  '┃ dict, set        │          │     ✓      │    ✓     ┃\n' +
+  '┃ iter             │          │            │    ✓     ┃\n' +
+  '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┛\n';
+
+const DIAGRAM_4_A =
+  '+--------------------+----------+----------+------+---------+--------+\n' +
+  '|                    | Integral | Rational | Real | Complex | Number |\n' +
+  '+--------------------+----------+----------+------+---------+--------+\n' +
+  '| int                |   yes    |   yes    | yes  |   yes   |  yes   |\n' +
+  '| fractions.Fraction |          |   yes    | yes  |   yes   |  yes   |\n' +
+  '| float              |          |          | yes  |   yes   |  yes   |\n' +
+  '| complex            |          |          |      |   yes   |  yes   |\n' +
+  '+--------------------+----------+----------+------+---------+--------+\n';
+
+const DIAGRAM_4_B =
+  '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┯━━━━━━━━━┯━━━━━━━━┓\n' +
+  '┃                    │ Integral │ Rational │ Real │ Complex │ Number ┃\n' +
+  '┠────────────────────┼──────────┼──────────┼──────┼─────────┼────────┨\n' +
+  '┃ int                │    ✓     │    ✓     │  ✓   │    ✓    │   ✓    ┃\n' +
+  '┃ fractions.Fraction │          │    ✓     │  ✓   │    ✓    │   ✓    ┃\n' +
+  '┃ float              │          │          │  ✓   │    ✓    │   ✓    ┃\n' +
+  '┃ complex            │          │          │      │    ✓    │   ✓    ┃\n' +
+  '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┷━━━━━━━━━┷━━━━━━━━┛\n';
+
 
 function main() {
   const html = getMd();
@@ -102,7 +140,10 @@ function getMd() {
 
 function switchClassDiagrams(readme) {
   readme = readme.replace(DIAGRAM_1_A, DIAGRAM_1_B)
-  return readme.replace(DIAGRAM_2_A, DIAGRAM_2_B)
+  readme = readme.replace(DIAGRAM_2_A, DIAGRAM_2_B)
+  readme = readme.replace(DIAGRAM_3_A, DIAGRAM_3_B)
+  readme = readme.replace(DIAGRAM_4_A, DIAGRAM_4_B)
+  return readme
 }
 
 function modifyPage() {
diff --git a/web/script_2.js b/web/script_2.js
index 91c7cc2..710c31f 100644
--- a/web/script_2.js
+++ b/web/script_2.js
@@ -42,6 +42,44 @@ const DIAGRAM_2_B =
   '┃   str   │             ┃\n' +
   '┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
 
+const DIAGRAM_3_A =
+  '+------------------+----------+------------+----------+\n' +
+  '|                  | Sequence | Collection | Iterable |\n' +
+  '+------------------+----------+------------+----------+\n' +
+  '| list, range, str |   yes    |    yes     |   yes    |\n' +
+  '| dict, set        |          |    yes     |   yes    |\n' +
+  '| iter             |          |            |   yes    |\n' +
+  '+------------------+----------+------------+----------+\n';
+
+const DIAGRAM_3_B =
+  '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┓\n' +
+  '┃                  │ Sequence │ Collection │ Iterable ┃\n' +
+  '┠──────────────────┼──────────┼────────────┼──────────┨\n' +
+  '┃ list, range, str │    ✓     │     ✓      │    ✓     ┃\n' +
+  '┃ dict, set        │          │     ✓      │    ✓     ┃\n' +
+  '┃ iter             │          │            │    ✓     ┃\n' +
+  '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┛\n';
+
+const DIAGRAM_4_A =
+  '+--------------------+----------+----------+------+---------+--------+\n' +
+  '|                    | Integral | Rational | Real | Complex | Number |\n' +
+  '+--------------------+----------+----------+------+---------+--------+\n' +
+  '| int                |   yes    |   yes    | yes  |   yes   |  yes   |\n' +
+  '| fractions.Fraction |          |   yes    | yes  |   yes   |  yes   |\n' +
+  '| float              |          |          | yes  |   yes   |  yes   |\n' +
+  '| complex            |          |          |      |   yes   |  yes   |\n' +
+  '+--------------------+----------+----------+------+---------+--------+\n';
+
+const DIAGRAM_4_B =
+  '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┯━━━━━━━━━┯━━━━━━━━┓\n' +
+  '┃                    │ Integral │ Rational │ Real │ Complex │ Number ┃\n' +
+  '┠────────────────────┼──────────┼──────────┼──────┼─────────┼────────┨\n' +
+  '┃ int                │    ✓     │    ✓     │  ✓   │    ✓    │   ✓    ┃\n' +
+  '┃ fractions.Fraction │          │    ✓     │  ✓   │    ✓    │   ✓    ┃\n' +
+  '┃ float              │          │          │  ✓   │    ✓    │   ✓    ┃\n' +
+  '┃ complex            │          │          │      │    ✓    │   ✓    ┃\n' +
+  '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┷━━━━━━━━━┷━━━━━━━━┛\n';
+
 
 // isFontAvailable:
 (function(d){function c(c){b.style.fontFamily=c;e.appendChild(b);f=b.clientWidth;e.removeChild(b);return f}var f,e=d.body,b=d.createElement("span");b.innerHTML=Array(100).join("wi");b.style.cssText=["position:absolute","width:auto","font-size:128px","left:-99999px"].join(" !important;");var g=c("monospace"),h=c("serif"),k=c("sans-serif");window.isFontAvailable=function(b){return g!==c(b+",monospace")||k!==c(b+",sans-serif")||h!==c(b+",serif")}})(document);
@@ -49,6 +87,8 @@ const DIAGRAM_2_B =
 if (!isFontAvailable('Menlo')) {
   $(`code:contains(${DIAGRAM_1_B})`).html(DIAGRAM_1_A);
   $(`code:contains(${DIAGRAM_2_B})`).html(DIAGRAM_2_A);
+  $(`code:contains(${DIAGRAM_3_B})`).html(DIAGRAM_3_A);
+  $(`code:contains(${DIAGRAM_4_B})`).html(DIAGRAM_4_A);
   // var htmlString = $('code:contains(ᴺᴱᵂ)').html().replace(/ᴺᴱᵂ/g, '');
   // $('code:contains(ᴺᴱᵂ)').html(htmlString);
 }

From de8c842468112bda60f19d225fecba0e23b710d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 19:43:28 +0200
Subject: [PATCH 4/9] Duck iterator

---
 README.md  | 18 ++++++++++++++++++
 index.html | 14 ++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/README.md b/README.md
index 1bd66b9..e1cd5d6 100644
--- a/README.md
+++ b/README.md
@@ -1046,6 +1046,24 @@ class MyCollection:
             yield el
 ```
 
+### Iterator
+```python
+class Counter:
+    def __init__(self):
+        self.i = 0
+    def __next__(self):
+        self.i += 1
+        return self.i
+    def __iter__(self):
+        return self
+```
+
+```python
+>>> counter = Counter()
+>>> next(counter), next(counter), next(counter)
+(1, 2, 3)
+```
+
 ### Callable
 ```python
 class Counter:
diff --git a/index.html b/index.html
index fea4acc..bc6664b 100644
--- a/index.html
+++ b/index.html
@@ -981,6 +981,20 @@ creature  = Creature(Point(0, for el in self.a:
             yield el
 
+

Iterator

+
class Counter:
+    def __init__(self):
+        self.i = 0
+    def __next__(self):
+        self.i += 1
+        return self.i
+    def __iter__(self):
+        return self
+
+
>>> counter = Counter()
+>>> next(counter), next(counter), next(counter)
+(1, 2, 3)
+

Callable

class Counter:
     def __init__(self):

From ee3fd66e7048c56325a951893cab20dd78e0b9fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 20:03:11 +0200
Subject: [PATCH 5/9] MyCollection

---
 README.md  | 7 +++++++
 index.html | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/README.md b/README.md
index e1cd5d6..ef227d3 100644
--- a/README.md
+++ b/README.md
@@ -1046,6 +1046,13 @@ class MyCollection:
             yield el
 ```
 
+```python
+>>> from collections.abc import Sequence, Collection, Iterable
+>>> a = MyCollection([1, 2, 3])
+>>> isinstance(a, Sequence), isinstance(a, Collection), isinstance(a, Iterable)
+(False, True, True)
+```
+
 ### Iterator
 ```python
 class Counter:
diff --git a/index.html b/index.html
index bc6664b..5ba62ac 100644
--- a/index.html
+++ b/index.html
@@ -981,6 +981,11 @@ creature  = Creature(Point(0, for el in self.a:
             yield el
 
+
>>> from collections.abc import Sequence, Collection, Iterable
+>>> a = MyCollection([1, 2, 3])
+>>> isinstance(a, Sequence), isinstance(a, Collection), isinstance(a, Iterable)
+(False, True, True)
+

Iterator

class Counter:
     def __init__(self):

From d38a6257f1e23870031da4839d472cdd26284e94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 21:45:34 +0200
Subject: [PATCH 6/9] List

---
 README.md  | 3 ++-
 index.html | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index ef227d3..5b94f57 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,8 @@ list_of_chars    = list()
 ```
 
 ```python
-index = .index()     # Returns first index of item or raises ValueError.
+ =  in   # For dictionary it checks if key exists.
+index = .index()     # Returns index of first occurrence or raises ValueError.
 .insert(index, )     # Inserts item at index and moves the rest to the right.
  = .pop([index])     # Removes and returns item at index or from the end.
 .remove()            # Removes first occurrence of item or raises ValueError.
diff --git a/index.html b/index.html
index 5ba62ac..6ca1328 100644
--- a/index.html
+++ b/index.html
@@ -237,7 +237,8 @@ flatter_list     = list(itertools.chain.from_iterable(<list>))
 product_of_elems = functools.reduce(lambda out, x: out * x, <collection>)
 list_of_chars    = list(<str>)
 
-
index = <list>.index(<el>)     # Returns first index of item or raises ValueError.
+
<bool> = <el> in <collection>  # For dictionary it checks if key exists.
+index = <list>.index(<el>)     # Returns index of first occurrence or raises ValueError.
 <list>.insert(index, <el>)     # Inserts item at index and moves the rest to the right.
 <el> = <list>.pop([index])     # Removes and returns item at index or from the end.
 <list>.remove(<el>)            # Removes first occurrence of item or raises ValueError.

From edfb7474d3fd1bf1434875ccaca2c557b494116e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 22:27:07 +0200
Subject: [PATCH 7/9] Tuple

---
 README.md  | 56 +++++++++++++++++++++++++++++++-----------------------
 index.html | 44 ++++++++++++++++++++++++------------------
 parse.js   |  2 +-
 3 files changed, 58 insertions(+), 44 deletions(-)

diff --git a/README.md b/README.md
index 5b94f57..ec39c66 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Comprehensive Python Cheatsheet
 
 Contents
 --------
-**   ** **1. Collections:** ** ** **[`List`](#list)**__,__ **[`Dict`](#dictionary)**__,__ **[`Set`](#set)**__,__ **[`Range`](#range)**__,__ **[`Enumerate`](#enumerate)**__,__ **[`Namedtuple`](#named-tuple)**__,__ **[`Iterator`](#iterator)**__,__ **[`Generator`](#generator)**__.__  
+**   ** **1. Collections:** ** ** **[`List`](#list)**__,__ **[`Dict`](#dictionary)**__,__ **[`Set`](#set)**__,__ **[`Tuple`](#tuple)**__,__ **[`Range`](#range)**__,__ **[`Enumerate`](#enumerate)**__,__ **[`Iterator`](#iterator)**__,__ **[`Generator`](#generator)**__.__  
 **   ** **2. Types:** **          **  **[`Type`](#type)**__,__ **[`String`](#string)**__,__ **[`Regex`](#regex)**__,__ **[`Format`](#format)**__,__ **[`Numbers`](#numbers)**__,__ **[`Combinatorics`](#combinatorics)**__,__ **[`Datetime`](#datetime)**__.__  
 **   ** **3. Syntax:** **         **  **[`Args`](#arguments)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Duck_Types`](#duck-types)**__,__ **[`Enum`](#enum)**__,__ **[`Exceptions`](#exceptions)**__.__  
 **   ** **4. System:** **        **  **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#path)**__,__ **[`Command_Execution`](#command-execution)**__.__  
@@ -127,13 +127,42 @@ Set
 .discard()                           # Doesn't raise an error.
 ```
 
-### Frozenset
-#### Is hashable, meaning it can be used as a key in a dictionary or as an element in a set.
+### Frozen Set
+* **Frozen set is immutable and hashable set.**
+* **It can be used as a key in a dictionary or as an element in a set.**
 ```python
  = frozenset()
 ```
 
 
+Tuple
+-----
+**Tuple is immutable and hashable list.**
+```python
+ = ()
+ = (, )
+ = (, , ...)
+```
+
+### Named Tuple
+**Named tuple is tuple's subclass with named elements.**
+
+```python
+>>> from collections import namedtuple
+>>> Point = namedtuple('Point', 'x y')
+>>> p = Point(1, y=2)
+Point(x=1, y=2)
+>>> p[0]
+1
+>>> p.x
+1
+>>> getattr(p, 'y')
+2
+>>> p._fields  # Or: Point._fields
+('x', 'y')
+```
+
+
 Range
 -----
 ```python
@@ -156,27 +185,6 @@ for i, el in enumerate( [, i_start]):
 ```
 
 
-Named Tuple
------------
-* **Tuple is an immutable and hashable list.**
-* **Named tuple is its subclass with named elements.**
-
-```python
->>> from collections import namedtuple
->>> Point = namedtuple('Point', 'x y')
->>> p = Point(1, y=2)
-Point(x=1, y=2)
->>> p[0]
-1
->>> p.x
-1
->>> getattr(p, 'y')
-2
->>> p._fields  # Or: Point._fields
-('x', 'y')
-```
-
-
 Iterator
 --------
 ```python
diff --git a/index.html b/index.html
index 6ca1328..954dba5 100644
--- a/index.html
+++ b/index.html
@@ -204,7 +204,7 @@ pre.prettyprint {
 
 

#Contents

ToC = {
-    '1. Collections': [List, Dict, Set, Range, Enumerate, Namedtuple, Iterator, Generator],
+    '1. Collections': [List, Dict, Set, Tuple, Range, Enumerate, Iterator, Generator],
     '2. Types':       [Type, String, Regex, Format, Numbers, Combinatorics, Datetime],
     '3. Syntax':      [Args, Inline, Closure, Decorator, Class, Duck_Types, Enum, Exceptions],
     '4. System':      [Print, Input, Command_Line_Arguments, Open, Path, Command_Execution],
@@ -286,27 +286,21 @@ Counter({'blue': 3<set>.remove(<el>)                            # Raises KeyError.
 <set>.discard(<el>)                           # Doesn't raise an error.
 
-

Frozenset

-

Is hashable, meaning it can be used as a key in a dictionary or as an element in a set.

+

Frozen Set

+
    +
  • Frozen set is immutable and hashable set.
  • +
  • It can be used as a key in a dictionary or as an element in a set.
  • +
<frozenset> = frozenset(<collection>)
 
-

#Range

-
<range> = range(to_exclusive)
-<range> = range(from_inclusive, to_exclusive)
-<range> = range(from_inclusive, to_exclusive, ±step_size)
-
-
from_inclusive = <range>.start
-to_exclusive   = <range>.stop
+

#Tuple

+

Tuple is immutable and hashable list.

+
<tuple> = ()
+<tuple> = (<el>, )
+<tuple> = (<el_1>, <el_2>, ...)
 
-

#Enumerate

-
for i, el in enumerate(<collection> [, i_start]):
-    ...
-
-

#Named Tuple

-
    -
  • Tuple is an immutable and hashable list.
  • -
  • Named tuple is its subclass with named elements.
  • -
+

Named Tuple

+

Named tuple is tuple's subclass with named elements.

>>> from collections import namedtuple
 >>> Point = namedtuple('Point', 'x y')
 >>> p = Point(1, y=2)
@@ -320,6 +314,18 @@ Point(x=1, y=2
 >>> p._fields  # Or: Point._fields
 ('x', 'y')
 
+

#Range

+
<range> = range(to_exclusive)
+<range> = range(from_inclusive, to_exclusive)
+<range> = range(from_inclusive, to_exclusive, ±step_size)
+
+
from_inclusive = <range>.start
+to_exclusive   = <range>.stop
+
+

#Enumerate

+
for i, el in enumerate(<collection> [, i_start]):
+    ...
+

#Iterator

from itertools import count, repeat, cycle, chain, islice
 
diff --git a/parse.js b/parse.js index f9ea021..d85dea5 100755 --- a/parse.js +++ b/parse.js @@ -19,7 +19,7 @@ const TOC = '
' + '

Contents

\n' + '
ToC = {\n' +
-  '    \'1. Collections\': [List, Dict, Set, Range, Enumerate, Namedtuple, Iterator, Generator],\n' +
+  '    \'1. Collections\': [List, Dict, Set, Tuple, Range, Enumerate, Iterator, Generator],\n' +
   '    \'2. Types\':       [Type, String, Regex, Format, Numbers, Combinatorics, Datetime],\n' +
   '    \'3. Syntax\':      [Args, Inline, Closure, Decorator, Class, Duck_Types, Enum, Exceptions],\n' +
   '    \'4. System\':      [Print, Input, Command_Line_Arguments, Open, Path, Command_Execution],\n' +

From 751770ae20b577298f46aa2d821e4479b2d49c84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 22:50:46 +0200
Subject: [PATCH 8/9] Tuple

---
 README.md  | 8 ++++----
 index.html | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index ec39c66..36fa0dd 100644
--- a/README.md
+++ b/README.md
@@ -128,8 +128,8 @@ Set
 ```
 
 ### Frozen Set
-* **Frozen set is immutable and hashable set.**
-* **It can be used as a key in a dictionary or as an element in a set.**
+* **Is immutable and hashable.**
+* **That means it can be used as a key in a dictionary or as an element in a set.**
 ```python
  = frozenset()
 ```
@@ -137,7 +137,7 @@ Set
 
 Tuple
 -----
-**Tuple is immutable and hashable list.**
+**Tuple is an immutable and hashable list.**
 ```python
  = ()
  = (, )
@@ -145,7 +145,7 @@ Tuple
 ```
 
 ### Named Tuple
-**Named tuple is tuple's subclass with named elements.**
+**Tuple's subclass with named elements.**
 
 ```python
 >>> from collections import namedtuple
diff --git a/index.html b/index.html
index 954dba5..144bb44 100644
--- a/index.html
+++ b/index.html
@@ -288,19 +288,19 @@ Counter({'blue': 3

Frozen Set

    -
  • Frozen set is immutable and hashable set.
  • -
  • It can be used as a key in a dictionary or as an element in a set.
  • +
  • Is immutable and hashable.
  • +
  • That means it can be used as a key in a dictionary or as an element in a set.
<frozenset> = frozenset(<collection>)
 

#Tuple

-

Tuple is immutable and hashable list.

+

Tuple is an immutable and hashable list.

<tuple> = ()
 <tuple> = (<el>, )
 <tuple> = (<el_1>, <el_2>, ...)
 

Named Tuple

-

Named tuple is tuple's subclass with named elements.

+

Tuple's subclass with named elements.

>>> from collections import namedtuple
 >>> Point = namedtuple('Point', 'x y')
 >>> p = Point(1, y=2)

From 720b1e2b44dd25b40e661f5f60a6509182afb9b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jure=20=C5=A0orn?= 
Date: Thu, 27 Jun 2019 23:27:07 +0200
Subject: [PATCH 9/9] Scraping

---
 README.md  | 38 ++++++++++++--------------------------
 index.html | 35 ++++++++++++-----------------------
 2 files changed, 24 insertions(+), 49 deletions(-)

diff --git a/README.md b/README.md
index 36fa0dd..915f399 100644
--- a/README.md
+++ b/README.md
@@ -1911,33 +1911,19 @@ retention=||
 
 Scraping
 --------
+#### Scrapes and prints Python's URL and version number from Wikipedia:
 ```python
 # $ pip3 install requests beautifulsoup4
->>> import requests
->>> from bs4 import BeautifulSoup
->>> url   = 'https://en.wikipedia.org/wiki/Python_(programming_language)'
->>> page  = requests.get(url)
->>> doc   = BeautifulSoup(page.text, 'html.parser')
->>> table = doc.find('table', class_='infobox vevent')
->>> rows  = table.find_all('tr')
->>> link  = rows[11].find('a')['href']
->>> ver   = rows[6].find('div').text.split()[0]
->>> link, ver
-('https://www.python.org/', '3.7.2')
-```
-
-### Selenium
-**Library for scraping dynamically generated web content.**
-
-```python
-# $ brew cask install chromedriver
-# $ pip3 install selenium
->>> from selenium import webdriver
->>> driver = webdriver.Chrome()
->>> driver.get(url)
->>> xpath  = '//*[@id="mw-content-text"]/div/table[1]/tbody/tr[7]/td/div'
->>> driver.find_element_by_xpath(xpath).text.split()[0]
-'3.7.2'
+import requests
+from bs4 import BeautifulSoup
+url   = 'https://en.wikipedia.org/wiki/Python_(programming_language)'
+page  = requests.get(url)
+doc   = BeautifulSoup(page.text, 'html.parser')
+table = doc.find('table', class_='infobox vevent')
+rows  = table.find_all('tr')
+link  = rows[11].find('a')['href']
+ver   = rows[6].find('div').text.split()[0]
+print(link, ver)
 ```
 
 
@@ -2049,7 +2035,7 @@ from datetime import datetime
 time_str = datetime.now().strftime('%Y%m%d%H%M%S')
 filename = f'profile-{time_str}.png'
 drawer = output.GraphvizOutput(output_file=filename)
-with PyCallGraph(output=drawer):
+with PyCallGraph(drawer):
     
 ```
 
diff --git a/index.html b/index.html
index 144bb44..0231f4b 100644
--- a/index.html
+++ b/index.html
@@ -1614,29 +1614,18 @@ logger.<level>('A logging message.')
 
  • '<str>' - Max age as a string: '1 week, 3 days', '2 months', …
  • #Scraping

    +

    Scrapes and prints Python's URL and version number from Wikipedia:

    # $ pip3 install requests beautifulsoup4
    ->>> import requests
    ->>> from bs4 import BeautifulSoup
    ->>> url   = 'https://en.wikipedia.org/wiki/Python_(programming_language)'
    ->>> page  = requests.get(url)
    ->>> doc   = BeautifulSoup(page.text, 'html.parser')
    ->>> table = doc.find('table', class_='infobox vevent')
    ->>> rows  = table.find_all('tr')
    ->>> link  = rows[11].find('a')['href']
    ->>> ver   = rows[6].find('div').text.split()[0]
    ->>> link, ver
    -('https://www.python.org/', '3.7.2')
    -
    -

    Selenium

    -

    Library for scraping dynamically generated web content.

    -
    # $ brew cask install chromedriver
    -# $ pip3 install selenium
    ->>> from selenium import webdriver
    ->>> driver = webdriver.Chrome()
    ->>> driver.get(url)
    ->>> xpath  = '//*[@id="mw-content-text"]/div/table[1]/tbody/tr[7]/td/div'
    ->>> driver.find_element_by_xpath(xpath).text.split()[0]
    -'3.7.2'
    +import requests
    +from bs4 import BeautifulSoup
    +url   = 'https://en.wikipedia.org/wiki/Python_(programming_language)'
    +page  = requests.get(url)
    +doc   = BeautifulSoup(page.text, 'html.parser')
    +table = doc.find('table', class_='infobox vevent')
    +rows  = table.find_all('tr')
    +link  = rows[11].find('a')['href']
    +ver   = rows[6].find('div').text.split()[0]
    +print(link, ver)
     

    #Web

    # $ pip3 install bottle
    @@ -1719,7 +1708,7 @@ Line #      Hits         Time  Per Hit   % Time  Line Contents
     time_str = datetime.now().strftime('%Y%m%d%H%M%S')
     filename = f'profile-{time_str}.png'
     drawer = output.GraphvizOutput(output_file=filename)
    -with PyCallGraph(output=drawer):
    +with PyCallGraph(drawer):
         <code_to_be_profiled>
     

    #NumPy