From 6a91771156a0c7a57e4a7d7ccc88ffc9e4a1fa16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 17 Feb 2022 00:15:06 +0100 Subject: [PATCH] Type, Regex, Numbers --- README.md | 25 ++++++++++---------- index.html | 27 +++++++++++----------- parse.js | 68 +++++++++++++++++++++++++++--------------------------- 3 files changed, 61 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index daf5ef8..2678e96 100644 --- a/README.md +++ b/README.md @@ -262,39 +262,39 @@ from types import FunctionType, MethodType, LambdaType, GeneratorType, ModuleTyp ``` ### Abstract Base Classes -**Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Collection ABC looks for methods iter(), contains() and len(), while Iterable ABC only looks for method iter().** +**Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Iterable ABC looks for method iter() while Collection ABC looks for methods iter(), contains() and len().** ```python ->>> from collections.abc import Sequence, Collection, Iterable +>>> from collections.abc import Iterable, Collection, Sequence >>> isinstance([1, 2, 3], Iterable) True ``` ```text +------------------+------------+------------+------------+ -| | Sequence | Collection | Iterable | +| | Iterable | Collection | Sequence | +------------------+------------+------------+------------+ | list, range, str | yes | yes | yes | -| dict, set | | yes | yes | -| iter | | | yes | +| dict, set | yes | yes | | +| iter | yes | | | +------------------+------------+------------+------------+ ``` ```python ->>> from numbers import Integral, Rational, Real, Complex, Number +>>> from numbers import Number, Complex, Real, Rational, Integral >>> isinstance(123, Number) True ``` ```text +--------------------+----------+----------+----------+----------+----------+ -| | Integral | Rational | Real | Complex | Number | +| | Number | Complex | Real | Rational | Integral | +--------------------+----------+----------+----------+----------+----------+ | int | yes | yes | yes | yes | yes | -| fractions.Fraction | | yes | yes | yes | yes | -| float | | | yes | yes | yes | -| complex | | | | yes | yes | -| decimal.Decimal | | | | | yes | +| fractions.Fraction | yes | yes | yes | yes | | +| float | yes | yes | yes | | | +| complex | yes | yes | | | | +| decimal.Decimal | yes | | | | | +--------------------+----------+----------+----------+----------+----------+ ``` @@ -360,6 +360,7 @@ import re = re.finditer(, text) # Returns all occurrences as match objects. ``` +* **Argument 'new' can be a function that accepts a match and returns a string.** * **Search() and match() return None if they can't find a match.** * **Argument `'flags=re.IGNORECASE'` can be used with all functions.** * **Argument `'flags=re.MULTILINE'` makes `'^'` and `'$'` match the start/end of each line.** @@ -510,7 +511,7 @@ from math import log, log10, log2 ### Statistics ```python -from statistics import mean, median, variance, stdev, pvariance, pstdev +from statistics import mean, median, variance, stdev, quantiles, groupby ``` ### Random diff --git a/index.html b/index.html index a62a1b7..3d79269 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -263,32 +263,32 @@ to_exclusive = <range>.stop

Some types do not have built-in names, so they must be imported:

from types import FunctionType, MethodType, LambdaType, GeneratorType, ModuleType
 
-

Abstract Base Classes

Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Collection ABC looks for methods iter(), contains() and len(), while Iterable ABC only looks for method iter().

>>> from collections.abc import Sequence, Collection, Iterable
+

Abstract Base Classes

Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Iterable ABC looks for method iter() while Collection ABC looks for methods iter(), contains() and len().

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

#String

<str>  = <str>.strip()                       # Strips all whitespace characters from both ends.
@@ -340,6 +340,7 @@ to_exclusive   = <range>.stop
 
    +
  • Argument 'new' can be a function that accepts a match and returns a string.
  • Search() and match() return None if they can't find a match.
  • Argument 'flags=re.IGNORECASE' can be used with all functions.
  • Argument 'flags=re.MULTILINE' makes '^' and '$' match the start/end of each line.
  • @@ -465,7 +466,7 @@ to_exclusive = <range>.stop from math import log, log10, log2
-

Statistics

from statistics import mean, median, variance, stdev, pvariance, pstdev
+

Statistics

from statistics import mean, median, variance, stdev, quantiles, groupby
 

Random

from random import random, randint, choice, shuffle, gauss, seed
@@ -2883,7 +2884,7 @@ $ pyinstaller script.py --add-data '<path>:.'  
  
 
   
 
diff --git a/parse.js b/parse.js
index 8e7348c..c77d68f 100755
--- a/parse.js
+++ b/parse.js
@@ -103,54 +103,54 @@ const INDEX =
 
 const DIAGRAM_1_A =
   '+------------------+------------+------------+------------+\n' +
-  '|                  |  Sequence  | Collection |  Iterable  |\n' +
+  '|                  |  Iterable  | Collection |  Sequence  |\n' +
   '+------------------+------------+------------+------------+\n';
 
-const DIAGRAM_1_B =
-  '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
-  '┃                  │  Sequence  │ Collection │  Iterable  ┃\n' +
-  '┠──────────────────┼────────────┼────────────┼────────────┨\n' +
-  '┃ list, range, str │     ✓      │     ✓      │     ✓      ┃\n' +
-  '┃ dict, set        │            │     ✓      │     ✓      ┃\n' +
-  '┃ iter             │            │            │     ✓      ┃\n' +
-  '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
-
 // const DIAGRAM_1_B =
-// '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
-// '┃                  │  Iterable  │ Collection │  Sequence  ┃\n' +
-// '┠──────────────────┼────────────┼────────────┼────────────┨\n' +
-// '┃ list, range, str │     ✓      │     ✓      │     ✓      ┃\n' +
-// '┃ dict, set        │     ✓      │     ✓      │            ┃\n' +
-// '┃ iter             │     ✓      │            │            ┃\n' +
-// '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
+//   '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
+//   '┃                  │  Sequence  │ Collection │  Iterable  ┃\n' +
+//   '┠──────────────────┼────────────┼────────────┼────────────┨\n' +
+//   '┃ list, range, str │     ✓      │     ✓      │     ✓      ┃\n' +
+//   '┃ dict, set        │            │     ✓      │     ✓      ┃\n' +
+//   '┃ iter             │            │            │     ✓      ┃\n' +
+//   '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
+
+const DIAGRAM_1_B =
+'┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
+'┃                  │  Iterable  │ Collection │  Sequence  ┃\n' +
+'┠──────────────────┼────────────┼────────────┼────────────┨\n' +
+'┃ list, range, str │     ✓      │     ✓      │     ✓      ┃\n' +
+'┃ dict, set        │     ✓      │     ✓      │            ┃\n' +
+'┃ iter             │     ✓      │            │            ┃\n' +
+'┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
 
 const DIAGRAM_2_A =
   '+--------------------+----------+----------+----------+----------+----------+\n' +
-  '|                    | Integral | Rational |   Real   | Complex  |  Number  |\n' +
+  '|                    |  Number  |  Complex |   Real   | Rational | Integral |\n' +
   '+--------------------+----------+----------+----------+----------+----------+\n';
 
-const DIAGRAM_2_B =
-  '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
-  '┃                    │ Integral │ Rational │   Real   │ Complex  │  Number  ┃\n' +
-  '┠────────────────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
-  '┃ int                │    ✓     │    ✓     │    ✓     │    ✓     │    ✓     ┃\n' +
-  '┃ fractions.Fraction │          │    ✓     │    ✓     │    ✓     │    ✓     ┃\n' +
-  '┃ float              │          │          │    ✓     │    ✓     │    ✓     ┃\n' +
-  '┃ complex            │          │          │          │    ✓     │    ✓     ┃\n' +
-  '┃ decimal.Decimal    │          │          │          │          │    ✓     ┃\n' +
-  '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
-
 // const DIAGRAM_2_B =
 //   '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
-//   '┃                    │  Number  │  Complex │   Real   │ Rational │ Integral ┃\n' +
+//   '┃                    │ Integral │ Rational │   Real   │ Complex  │  Number  ┃\n' +
 //   '┠────────────────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
 //   '┃ int                │    ✓     │    ✓     │    ✓     │    ✓     │    ✓     ┃\n' +
-//   '┃ fractions.Fraction │    ✓     │    ✓     │    ✓     │    ✓     │          ┃\n' +
-//   '┃ float              │    ✓     │    ✓     │    ✓     │          │          ┃\n' +
-//   '┃ complex            │    ✓     │    ✓     │          │          │          ┃\n' +
-//   '┃ decimal.Decimal    │    ✓     │          │          │          │          ┃\n' +
+//   '┃ fractions.Fraction │          │    ✓     │    ✓     │    ✓     │    ✓     ┃\n' +
+//   '┃ float              │          │          │    ✓     │    ✓     │    ✓     ┃\n' +
+//   '┃ complex            │          │          │          │    ✓     │    ✓     ┃\n' +
+//   '┃ decimal.Decimal    │          │          │          │          │    ✓     ┃\n' +
 //   '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
 
+const DIAGRAM_2_B =
+  '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
+  '┃                    │  Number  │  Complex │   Real   │ Rational │ Integral ┃\n' +
+  '┠────────────────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
+  '┃ int                │    ✓     │    ✓     │    ✓     │    ✓     │    ✓     ┃\n' +
+  '┃ fractions.Fraction │    ✓     │    ✓     │    ✓     │    ✓     │          ┃\n' +
+  '┃ float              │    ✓     │    ✓     │    ✓     │          │          ┃\n' +
+  '┃ complex            │    ✓     │    ✓     │          │          │          ┃\n' +
+  '┃ decimal.Decimal    │    ✓     │          │          │          │          ┃\n' +
+  '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
+
 const DIAGRAM_3_A =
   '+---------------+----------+----------+----------+----------+----------+\n';