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' +