From 8b2fac3b0aeed4a1ddaf2f71c5a33263fff8e554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 23 Jun 2022 07:51:01 +0200 Subject: [PATCH] Set, Inline - a lot of changes --- README.md | 38 +++++++++++++++++++------------------- index.html | 42 +++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index f203487..0b429de 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Counter({'blue': 3, 'red': 2, 'yellow': 1}) Set --- ```python - = set() + = set() # {} returns a dictionary. ``` ```python @@ -752,16 +752,16 @@ Inline ------ ### Lambda ```python - = lambda: # A single statement function. - = lambda , : # Also accepts default arguments. + = lambda: # A single statement function. + = lambda , : # Also accepts default arguments. ``` ### Comprehensions ```python - = [i+1 for i in range(10)] # Or: [1, 2, ..., 10] - = (i for i in range(10) if i > 5) # Or: iter([6, 7, 8, 9]) - = {i+5 for i in range(10)} # Or: {5, 6, ..., 14} - = {i: i*2 for i in range(10)} # Or: {0: 0, 1: 2, ..., 9: 18} + = [i+1 for i in range(10)] # Or: [1, 2, ..., 10] + = (i for i in range(10) if i > 5) # Or: iter([6, 7, 8, 9]) + = {i+5 for i in range(10)} # Or: {5, 6, ..., 14} + = {i: i*2 for i in range(10)} # Or: {0: 0, 1: 2, ..., 9: 18} ``` ```python @@ -771,21 +771,21 @@ Inline ### Map, Filter, Reduce ```python - = map(lambda x: x + 1, range(10)) # Or: iter([1, 2, ..., 10]) - = filter(lambda x: x > 5, range(10)) # Or: iter([6, 7, 8, 9]) - = reduce(lambda out, x: out + x, range(10)) # Or: 45 + = map(lambda x: x + 1, range(10)) # Or: iter([1, 2, ..., 10]) + = filter(lambda x: x > 5, range(10)) # Or: iter([6, 7, 8, 9]) + = reduce(lambda out, x: out + x, range(10)) # Or: 45 ``` * **Reduce must be imported from the functools module.** ### Any, All ```python - = any() # Is `bool(el)` True for any element. - = all() # Is True for all elements or empty. + = any() # Is `bool(el)` True for any element. + = all() # Is True for all elements or empty. ``` ### Conditional Expression ```python - = if else # Only one expression gets evaluated. + = if else # Only one expression gets evaluated. ``` ```python @@ -796,20 +796,20 @@ Inline ### Named Tuple, Enum, Dataclass ```python from collections import namedtuple -Point = namedtuple('Point', 'x y') -point = Point(0, 0) +Point = namedtuple('Point', 'x y') # Tuple's subclass with named elements. +point = Point(0, 0) # Tuple with x and y attributes. ``` ```python from enum import Enum -Direction = Enum('Direction', 'n e s w') -direction = Direction.n +Direction = Enum('Direction', 'n e s w') # Enum with n, e, s and w members. +direction = Direction.n # Member with name and value attributes. ``` ```python from dataclasses import make_dataclass -Creature = make_dataclass('Creature', ['loc', 'dir']) -creature = Creature(point, direction) +Player = make_dataclass('Player', ['loc', 'dir']) # Class with init, repr and eq methods. +player = Player(point, direction) # Object with loc and dir attributes. ``` diff --git a/index.html b/index.html index 39a39a9..04328c9 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -158,7 +158,7 @@ Counter({'blue': 3'blue', 3) -

#Set

<set> = set()
+

#Set

<set> = set()                                   # {} returns a dictionary.
 
<set>.add(<el>)                                 # Or: <set> |= {<el>}
@@ -647,50 +647,50 @@ func(*args, **kwargs)
 
 
head, *body, tail = <coll.>     # Head or tail can be omitted.
 
-

#Inline

Lambda

<func> = lambda: <return_value>                           # A single statement function.
-<func> = lambda <arg_1>, <arg_2>: <return_value>          # Also accepts default arguments.
+

#Inline

Lambda

<func> = lambda: <return_value>                     # A single statement function.
+<func> = lambda <arg_1>, <arg_2>: <return_value>    # Also accepts default arguments.
 
-

Comprehensions

<list> = [i+1 for i in range(10)]                         # Or: [1, 2, ..., 10]
-<iter> = (i for i in range(10) if i > 5)                  # Or: iter([6, 7, 8, 9])
-<set>  = {i+5 for i in range(10)}                         # Or: {5, 6, ..., 14}
-<dict> = {i: i*2 for i in range(10)}                      # Or: {0: 0, 1: 2, ..., 9: 18}
+

Comprehensions

<list> = [i+1 for i in range(10)]                   # Or: [1, 2, ..., 10]
+<iter> = (i for i in range(10) if i > 5)            # Or: iter([6, 7, 8, 9])
+<set>  = {i+5 for i in range(10)}                   # Or: {5, 6, ..., 14}
+<dict> = {i: i*2 for i in range(10)}                # Or: {0: 0, 1: 2, ..., 9: 18}
 
>>> [l+r for l in 'abc' for r in 'abc']
 ['aa', 'ab', 'ac', ..., 'cc']
 
-

Map, Filter, Reduce

<iter> = map(lambda x: x + 1, range(10))                  # Or: iter([1, 2, ..., 10])
-<iter> = filter(lambda x: x > 5, range(10))               # Or: iter([6, 7, 8, 9])
-<obj>  = reduce(lambda out, x: out + x, range(10))        # Or: 45
+

Map, Filter, Reduce

<iter> = map(lambda x: x + 1, range(10))            # Or: iter([1, 2, ..., 10])
+<iter> = filter(lambda x: x > 5, range(10))         # Or: iter([6, 7, 8, 9])
+<obj>  = reduce(lambda out, x: out + x, range(10))  # Or: 45
 
  • Reduce must be imported from the functools module.
-

Any, All

<bool> = any(<collection>)                                # Is `bool(el)` True for any element.
-<bool> = all(<collection>)                                # Is True for all elements or 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>  # Only one expression gets evaluated.
+

Conditional Expression

<obj> = <exp> if <condition> else <exp>             # Only one expression gets evaluated.
 
>>> [a if a else 'zero' for a in (0, 1, 2, 3)]
 ['zero', 1, 2, 3]
 

Named Tuple, Enum, Dataclass

from collections import namedtuple
-Point = namedtuple('Point', 'x y')
-point = Point(0, 0)
+Point = namedtuple('Point', 'x y')                  # Tuple's subclass with named elements.
+point = Point(0, 0)                                 # Tuple with x and y attributes.
 
from enum import Enum
-Direction = Enum('Direction', 'n e s w')
-direction = Direction.n
+Direction = Enum('Direction', 'n e s w')            # Enum with n, e, s and w members.
+direction = Direction.n                             # Member with name and value attributes.
 
from dataclasses import make_dataclass
-Creature = make_dataclass('Creature', ['loc', 'dir'])
-creature = Creature(point, direction)
+Player = make_dataclass('Player', ['loc', 'dir'])   # Class with init, repr and eq methods.
+player = Player(point, direction)                   # Object with loc and dir attributes.
 

#Imports

import <module>            # Imports a built-in or '<module>.py'.
 import <package>           # Imports a built-in or '<package>/__init__.py'.
@@ -2901,7 +2901,7 @@ $ pyinstaller script.py --add-data '<path>:.'