You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-38Lines changed: 36 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1262,8 +1262,7 @@ class MyCollection:
1262
1262
```
1263
1263
1264
1264
### Sequence
1265
-
***Only required methods are getitem() and len().**
1266
-
***Getitem() should return an item at the passed index or raise IndexError.**
1265
+
***Only required methods are getitem() and len(). Getitem() should return the item at the passed index or raise IndexError (this excludes dictionaries because they accept keys).**
1267
1266
***Iter() and contains() automatically work on any object that has getitem() defined.**
1268
1267
***Reversed() automatically works on any object that has getitem() and len() defined. It returns reversed iterator of object's items.**
1269
1268
```python
@@ -1287,8 +1286,8 @@ class MySequence:
1287
1286
***Passing ABC Iterable to isinstance() or issubclass() only checks whether object/class has special method iter(), while ABC Collection checks for iter(), contains() and len().**
1288
1287
1289
1288
### ABC Sequence
1290
-
***It's a richer interface than the basic sequence.**
1291
-
***Extending it generates iter(), contains(), reversed(), index() and count().**
1289
+
***It's a richer interface than the basic sequence that also just requires getitem() and len().**
1290
+
***Extending it generates iter(), contains(), reversed(), index() and count() special methods.**
1292
1291
***Unlike `'abc.Iterable'` and `'abc.Collection'`, it is not a duck type. That is why `'issubclass(MySequence, abc.Sequence)'` would return False even if MySequence had all the methods defined. It however recognizes list, tuple, range, str, bytes, bytearray, array, memoryview and deque, since they are registered as Sequence's virtual subclasses.**
1293
1292
```python
1294
1293
from collections import abc
@@ -1885,7 +1884,7 @@ import sqlite3
1885
1884
### Read
1886
1885
```python
1887
1886
<cursor>=<conn>.execute('<query>') # Can raise a subclass of sqlite3.Error.
1888
-
<tuple>=<cursor>.fetchone() # Returns next row. Also next(<cursor>).
1887
+
<tuple>=<cursor>.fetchone() # Returns the next row. Also next(<cursor>).
1889
1888
<list>=<cursor>.fetchall() # Returns remaining rows. Also list(<cursor>).
1890
1889
```
1891
1890
@@ -1905,7 +1904,7 @@ with <conn>: # Exits the block with commit() o
1905
1904
### Placeholders
1906
1905
```python
1907
1906
<conn>.execute('<query>', <list/tuple>) # Replaces every question mark with an item.
1908
-
<conn>.execute('<query>', <dict/namedtuple>) # Replaces every :<key> with matching value.
1907
+
<conn>.execute('<query>', <dict/namedtuple>) # Replaces every :<key> with a matching value.
1909
1908
<conn>.executemany('<query>', <coll_of_coll>) # Runs execute() once for each collection.
1910
1909
```
1911
1910
***Passed values can be of type str, int, float, bytes, None, or bool (stored as 1 or 0).**
**List that can only hold numbers of a predefined type. Available types and their minimum sizes in bytes are listed above. Type sizes and byte order are always determined by the system, however bytes of each element can be reversed with byteswap() method.**
2031
+
**List that can only hold numbers of a predefined C type. Available types and their minimum sizes in bytes are listed above. Type sizes and byte order are always determined by the system, however bytes of each element can be reversed with byteswap() method.**
2033
2032
2034
2033
```python
2035
2034
from array import array
2036
2035
```
2037
2036
2038
2037
```python
2039
-
<array>= array('<typecode>', <coll_of_nums>) # Creates array from collection of numbers.
2040
-
<array>= array('<typecode>', <bytes>) # Writes passed bytes to array's memory.
2038
+
<array>= array('<typecode>', <coll_of_nums>) # Creates an array from collection of numbers.
2039
+
<array>= array('<typecode>', <bytes>) # Writes passed bytes to the array's memory.
2041
2040
<array>= array('<typecode>', <array>) # Treats passed array as a sequence of numbers.
2042
-
<array>.fromfile(<file>, n_items) # Appends file's contents to array's memory.
2041
+
<array>.fromfile(<file>, n_items) # Appends file contents to the array's memory.
2043
2042
```
2044
2043
2045
2044
```python
2046
-
<bytes>=bytes(<array>) # Returns a copy of array's memory.
2045
+
<bytes>=bytes(<array>) # Returns a copy of array's memory as bytes.
2047
2046
<file>.write(<array>) # Writes array's memory to the binary file.
2048
2047
```
2049
2048
@@ -2054,7 +2053,7 @@ Memory View
2054
2053
2055
2054
```python
2056
2055
<mview>=memoryview(<bytes/bytearray/array>) # Immutable if bytes is passed, else mutable.
2057
-
<obj>=<mview>[index] # Returns int/float. Bytes if format is 'c'.
2056
+
<obj>=<mview>[index] # Returns ints/floats. Bytes if format is 'c'.
2058
2057
<mview>=<mview>[<slice>] # Returns memoryview with rearranged elements.
2059
2058
<mview>=<mview>.cast('<typecode>') # Only works between B/b/c and other types.
2060
2059
<mview>.release() # Releases memory buffer of the base object.
@@ -2069,7 +2068,7 @@ Memory View
2069
2068
2070
2069
```python
2071
2070
<list>=list(<mview>) # Returns a list of ints, floats or bytes.
2072
-
<str>=str(<mview>, 'utf-8') # Treats memoryview as a bytes object.
2071
+
<str>=str(<mview>, 'utf-8') # Treats passed memoryview as a bytes object.
<deque>.extendleft(<collection>) #Appends elements in reversed order.
2088
+
<deque>.rotate(n=1) # Last element becomes the first one.
2090
2089
<el>=<deque>.popleft() # Raises IndexError if deque is empty.
2091
2090
```
2092
2091
2093
2092
2094
2093
Operator
2095
2094
--------
2096
-
**Module of functions that provide the functionality of operators. Functions are grouped by operator precedence, from least to most binding. Functions and operators in lines 1, 3 and 5 are also ordered by precedence within a group.**
2095
+
**Module of functions that provide the functionality of operators. Functions are grouped by operator precedence, from least to most binding. Functions and operators in first, third and fifth line are also ordered by precedence within a group.**
2097
2096
```python
2098
2097
import operator as op
2099
2098
```
2100
2099
2101
2100
```python
2102
2101
<bool>= op.not_(<obj>) # or, and, not (or/and missing)
2103
2102
<bool>= op.eq/ne/lt/ge/is_/is_not/contains(<obj>, <obj>) # ==, !=, <, >=, is, is not, in
0 commit comments