From d07ca15537bcbfa479789ec61924472c1d8da2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 7 Jun 2022 14:42:42 +0200 Subject: [PATCH] Format --- README.md | 5 ++++- index.html | 4 +++- parse.js | 26 ++++++-------------------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index ee4e421..b286188 100644 --- a/README.md +++ b/README.md @@ -398,7 +398,8 @@ Format ### Attributes ```python ->>> Person = collections.namedtuple('Person', 'name height') +>>> from collections import namedtuple +>>> Person = namedtuple('Person', 'name height') >>> person = Person('Jean-Luc', 187) >>> f'{person.height}' '187' @@ -457,7 +458,9 @@ Format | 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' | | 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' | +--------------+----------------+----------------+----------------+----------------+ +``` +```text +--------------+----------------+----------------+----------------+----------------+ | | {:.2} | {:.2f} | {:.2e} | {:.2%} | +--------------+----------------+----------------+----------------+----------------+ diff --git a/index.html b/index.html index 046c2da..3a7a6b2 100644 --- a/index.html +++ b/index.html @@ -369,7 +369,8 @@ to_exclusive = <range>.stop <str> = '%s, %s' % (<el_1>, <el_2>) # Redundant and inferior C style formatting. -

Attributes

>>> Person = collections.namedtuple('Person', 'name height')
+

Attributes

>>> from collections import namedtuple
+>>> Person = namedtuple('Person', 'name height')
 >>> person = Person('Jean-Luc', 187)
 >>> f'{person.height}'
 '187'
@@ -434,6 +435,7 @@ to_exclusive   = <range>.stop
 ┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛
 
+

 
  • When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. That makes '{6.5:.0f}' a '6' and '{7.5:.0f}' an '8'.
  • This rule only effects numbers that can be represented exactly by a float (.5, .25, …).
  • diff --git a/parse.js b/parse.js index f2e719e..41c7078 100755 --- a/parse.js +++ b/parse.js @@ -112,15 +112,6 @@ const DIAGRAM_1_A = '| | 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' + @@ -135,17 +126,6 @@ const DIAGRAM_2_A = '| | 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' + @@ -201,6 +181,11 @@ const DIAGRAM_4_B = "┃ 56.789 │ '5.7e+01' │ '56.79' │ '5.68e+01' │ '5678.90%' ┃\n" + "┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛\n"; +const DIAGRAM_5_A = + "+--------------+----------------+----------------+----------------+----------------+\n" + + "| | {:.2} | {:.2f} | {:.2e} | {:.2%} |\n" + + "+--------------+----------------+----------------+----------------+----------------+\n"; + const DIAGRAM_6_A = '+------------+------------+------------+------------+--------------+\n' + '| | Iterable | Collection | Sequence | abc.Sequence |\n' + @@ -530,6 +515,7 @@ function updateDiagrams() { $(`code:contains(${DIAGRAM_2_A})`).html(DIAGRAM_2_B); $(`code:contains(${DIAGRAM_3_A})`).html(DIAGRAM_3_B); $(`code:contains(${DIAGRAM_4_A})`).html(DIAGRAM_4_B); + $(`code:contains(${DIAGRAM_5_A})`).remove(); $(`code:contains(${DIAGRAM_6_A})`).html(DIAGRAM_6_B); $(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B); $(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B);