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
<int>=<int><< n_bits # Left shift. Use >> for right.
559
+
<int>=~<int># Not. Also -<int> - 1.
555
560
```
556
561
557
562
@@ -562,30 +567,24 @@ import itertools as it
562
567
```
563
568
564
569
```python
565
-
>>>list(it.product([0, 1], repeat=3))
566
-
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1),
567
-
(1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
570
+
>>>list(it.product('abc', repeat=2)) # a b c
571
+
[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x
572
+
('b', 'a'), ('b', 'b'), ('b', 'c'), # b x x x
573
+
('c', 'a'), ('c', 'b'), ('c', 'c')] # c x x x
568
574
```
569
575
570
576
```python
571
-
>>>list(it.product('abc', 'abc')) # a b c
572
-
[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x
573
-
('b', 'a'), ('b', 'b'), ('b', 'c'),# b x x x
574
-
('c', 'a'), ('c', 'b'), ('c', 'c')]# c x x x
577
+
>>>list(it.permutations('abc', 2))# a b c
578
+
[('a', 'b'), ('a', 'c'), # a . x x
579
+
('b', 'a'), ('b', 'c'), # b x . x
580
+
('c', 'a'), ('c', 'b')] # c x x .
575
581
```
576
582
577
583
```python
578
-
>>>list(it.permutations('abc', 2)) # a b c
579
-
[('a', 'b'), ('a', 'c'), # a . x x
580
-
('b', 'a'), ('b', 'c'), # b x . x
581
-
('c', 'a'), ('c', 'b')] # c x x .
582
-
```
583
-
584
-
```python
585
-
>>>list(it.combinations('abc', 2)) # a b c
586
-
[('a', 'b'), ('a', 'c'), # a . x x
587
-
('b', 'c'), # b . . x
588
-
] # c . . .
584
+
>>>list(it.combinations('abc', 2)) # a b c
585
+
[('a', 'b'), ('a', 'c'), # a . x x
586
+
('b', 'c'), # b . . x
587
+
] # c . . .
589
588
```
590
589
591
590
@@ -1183,7 +1182,7 @@ class Counter:
1183
1182
1184
1183
### Callable
1185
1184
***All functions and classes have a call() method, hence are callable.**
1186
-
***Use `'callable(<obj>)'` or `'isinstance(<obj>, collections.abc.Callable)'` to check if object is callable.**
1185
+
***Use `'callable(<obj>)'` or `'isinstance(<obj>, collections.abc.Callable)'` to check if object is callable. Calling an uncallable object raises `'TypeError'`.**
1187
1186
***When this cheatsheet uses `'<function>'` as an argument, it means `'<callable>'`.**
1188
1187
```python
1189
1188
classCounter:
@@ -2435,7 +2434,7 @@ Console App
2435
2434
```python
2436
2435
# $ pip3 install windows-curses
2437
2436
import curses, os
2438
-
from curses importA_REVERSE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER
2437
+
from curses importA_REVERSE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
2439
2438
2440
2439
defmain(screen):
2441
2440
ch, first, selected, paths =0, 0, 0, os.listdir()
@@ -2450,7 +2449,7 @@ def main(screen):
2450
2449
selected += (ch ==KEY_DOWN) and (selected <len(paths)-1)
2451
2450
first -= (first > selected)
2452
2451
first += (first < selected-(height-1))
2453
-
if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord('\n'), ord('\r')]:
***Install a WSGI server like [Waitress](https://flask.palletsprojects.com/en/latest/deploying/waitress/) and a HTTP server such as [Nginx](https://flask.palletsprojects.com/en/latest/deploying/nginx/) for better security.**
2553
2552
***Debug mode restarts the app whenever script changes and displays errors in the browser.**
0 commit comments