diff --git a/README.md b/README.md index 19637c4..26e451a 100644 --- a/README.md +++ b/README.md @@ -732,10 +732,10 @@ def f(x, *args, z, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3 ### Other Uses ```python - = [* [, ...]] - = {* [, ...]} - = (*, [...]) - = {** [, ...]} + = [* [, ...]] + = {* [, ...]} + = (*, [...]) + = {** [, ...]} ``` ```python @@ -774,8 +774,8 @@ Inline ### Any, All ```python - = any() # False if empty. - = all(el[1] for el in ) # True if empty. + = any() # Is `bool(el)` True for any element. + = all() # Is True for all elements or empty. ``` ### Conditional Expression @@ -788,11 +788,11 @@ Inline ['zero', 1, 2, 3] ``` -### Namedtuple, Enum, Dataclass +### Named Tuple, Enum, Dataclass ```python from collections import namedtuple -Point = namedtuple('Point', 'x y') -point = Point(0, 0) +Point = namedtuple('Point', 'x y') +point = Point(0, 0) ``` ```python @@ -803,8 +803,8 @@ direction = Direction.n ```python from dataclasses import make_dataclass -Creature = make_dataclass('Creature', ['loc', 'dir']) -creature = Creature(Point(0, 0), Direction.n) +Creature = make_dataclass('Creature', ['loc', 'dir']) +creature = Creature(point, direction) ``` diff --git a/index.html b/index.html index e62fe06..6a3e2e7 100644 --- a/index.html +++ b/index.html @@ -226,7 +226,7 @@ pre.prettyprint {
- +
@@ -786,10 +786,10 @@ func(*args, **kwargs) def f(*args, y, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) def f(x, *args, z, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) -

Other Uses

<list> = [*<collection> [, ...]]
-<set>  = {*<collection> [, ...]}
-<tup.> = (*<collection>, [...])
-<dict> = {**<dict> [, ...]}
+

Other Uses

<list>  = [*<collection> [, ...]]
+<set>   = {*<collection> [, ...]}
+<tuple> = (*<collection>, [...])
+<dict>  = {**<dict> [, ...]}
 
head, *body, tail = <collection>
@@ -816,8 +816,8 @@ func(*args, **kwargs)
 
  • Reduce must be imported from functools module.
-

Any, All

<bool> = any(<collection>)                                # False if empty.
-<bool> = all(el[1] for el in <collection>)                # True if empty.
+

Any, All

<bool> = any(<collection>)                                # Is `bool(el)` True for any element.
+<bool> = all(<collection>)                                # Is True for all elements or empty.
 

Conditional Expression

<obj> = <exp_if_true> if <condition> else <exp_if_false>
@@ -826,9 +826,9 @@ func(*args, **kwargs)
 
>>> [a if a else 'zero' for a in (0, 1, 2, 3)]
 ['zero', 1, 2, 3]
 
-

Namedtuple, Enum, Dataclass

from collections import namedtuple
-Point     = namedtuple('Point', 'x y')
-point     = Point(0, 0)
+

Named Tuple, Enum, Dataclass

from collections import namedtuple
+Point = namedtuple('Point', 'x y')
+point = Point(0, 0)
 
from enum import Enum
@@ -836,8 +836,8 @@ Direction = Enum('Direction', from dataclasses import make_dataclass
-Creature  = make_dataclass('Creature', ['loc', 'dir'])
-creature  = Creature(Point(0, 0), Direction.n)
+Creature = make_dataclass('Creature', ['loc', 'dir'])
+creature = Creature(point, direction)
 

#Closure

We have a closure in Python when:

  • A nested function references a value of its enclosing function and then
  • @@ -3005,7 +3005,7 @@ $ pyinstaller script.py --add-data '<path>:.'