@@ -390,32 +390,14 @@ Numbers
390
390
< real> = round (< real> , ±ndigits)
391
391
```
392
392
393
- ### Constants
393
+ ### Math
394
394
``` python
395
395
from math import e, pi
396
- ```
397
-
398
- ### Trigonometry
399
- ``` python
400
396
from math import cos, acos, sin, asin, tan, atan, degrees, radians
401
- ```
402
-
403
- ### Logarithm
404
- ``` python
405
397
from math import log, log10, log2
406
- < float > = log(< real> [, base]) # Base e, if not specified.
407
- ```
408
-
409
- ### Infinity, nan
410
- ``` python
411
398
from math import inf, nan, isinf, isnan
412
399
```
413
400
414
- #### Or:
415
- ``` python
416
- float (' inf' ), float (' nan' )
417
- ```
418
-
419
401
### Statistics
420
402
``` python
421
403
from statistics import mean, median, variance, pvariance, pstdev
@@ -444,19 +426,27 @@ from itertools import product, combinations, combinations_with_replacement, perm
444
426
>> > product([0 , 1 ], repeat = 3 )
445
427
[(0 , 0 , 0 ), (0 , 0 , 1 ), (0 , 1 , 0 ), (0 , 1 , 1 ),
446
428
(1 , 0 , 0 ), (1 , 0 , 1 ), (1 , 1 , 0 ), (1 , 1 , 1 )]
429
+ ```
447
430
431
+ ``` python
448
432
>> > product(' ab' , ' 12' )
449
433
[(' a' , ' 1' ), (' a' , ' 2' ),
450
434
(' b' , ' 1' ), (' b' , ' 2' )]
435
+ ```
451
436
437
+ ``` python
452
438
>> > combinations(' abc' , 2 )
453
439
[(' a' , ' b' ), (' a' , ' c' ), (' b' , ' c' )]
440
+ ```
454
441
442
+ ``` python
455
443
>> > combinations_with_replacement(' abc' , 2 )
456
444
[(' a' , ' a' ), (' a' , ' b' ), (' a' , ' c' ),
457
445
(' b' , ' b' ), (' b' , ' c' ),
458
446
(' c' , ' c' )]
447
+ ```
459
448
449
+ ``` python
460
450
>> > permutations(' abc' , 2 )
461
451
[(' a' , ' b' ), (' a' , ' c' ),
462
452
(' b' , ' a' ), (' b' , ' c' ),
@@ -469,9 +459,9 @@ Datetime
469
459
``` python
470
460
from datetime import datetime
471
461
now = datetime.now()
472
- now.month # 3
473
- now.strftime(' %Y%m%d ' ) # '20180315'
474
- now.strftime(' %Y%m%d %H%M%S' ) # '20180315002834'
462
+ now.month # 3
463
+ now.strftime(' %Y%m%d ' ) # '20180315'
464
+ now.strftime(' %Y%m%d %H%M%S' ) # '20180315002834'
475
465
< datetime> = datetime.strptime(' 2015-05-12 00:39' , ' %Y-%m-%d %H:%M' )
476
466
```
477
467
@@ -520,7 +510,7 @@ def add(*a):
520
510
6
521
511
```
522
512
523
- #### Legal argument combinations with calls :
513
+ #### Legal argument combinations:
524
514
``` python
525
515
def f (* args ): # f(1, 2, 3)
526
516
def f (x , * args ): # f(1, 2, 3)
@@ -542,15 +532,14 @@ def f(x, *args, z, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3
542
532
543
533
### Other Uses
544
534
``` python
545
- >> > a = (1 , 2 , 3 )
546
- >> > [* a]
547
- [1 , 2 , 3 ]
535
+ < list > = [* < collection> [, ... ]]
536
+ < set > = {* < collection> [, ... ]}
537
+ < tuple > = (* < collection> , [... ])
538
+ < dict > = {** < dict > [, ... ]}
548
539
```
549
540
550
541
``` python
551
- >> > head, * body, tail = [1 , 2 , 3 , 4 ]
552
- >> > body
553
- [2 , 3 ]
542
+ head, * body, tail = < collection>
554
543
```
555
544
556
545
@@ -566,8 +555,8 @@ Inline
566
555
``` python
567
556
< list > = [i+ 1 for i in range (10 )] # [1, 2, ..., 10]
568
557
< set > = {i for i in range (10 ) if i > 5 } # {6, 7, 8, 9}
569
- < dict > = {i: i* 2 for i in range (10 )} # {0: 0, 1: 2, ..., 9: 18}
570
558
< iter > = (i+ 5 for i in range (10 )) # (5, 6, ..., 14)
559
+ < dict > = {i: i* 2 for i in range (10 )} # {0: 0, 1: 2, ..., 9: 18}
571
560
```
572
561
573
562
``` python
@@ -665,11 +654,11 @@ from functools import partial
665
654
666
655
``` python
667
656
def get_counter ():
668
- a = 0
657
+ i = 0
669
658
def out ():
670
- nonlocal a
671
- a += 1
672
- return a
659
+ nonlocal i
660
+ i += 1
661
+ return i
673
662
return out
674
663
```
675
664
@@ -721,6 +710,8 @@ def fib(n):
721
710
return n if n < 2 else fib(n- 2 ) + fib(n- 1 )
722
711
```
723
712
713
+ * ** Recursion depth is limited to 1000 by default. To increase it use ` 'sys.setrecursionlimit(<depth>)' ` .**
714
+
724
715
### Parametrized Decorator
725
716
``` python
726
717
from functools import wraps
@@ -839,8 +830,8 @@ class Counter:
839
830
```
840
831
841
832
``` python
842
- >> > c = Counter()
843
- >> > c (), c (), c ()
833
+ >> > counter = Counter()
834
+ >> > counter (), counter (), counter ()
844
835
(1 , 2 , 3 )
845
836
```
846
837
@@ -1115,16 +1106,6 @@ b'.\n..\nfile1.txt\nfile2.txt\n'
1115
1106
```
1116
1107
1117
1108
1118
- Recursion Limit
1119
- ---------------
1120
- ``` python
1121
- >> > import sys
1122
- >> > sys.getrecursionlimit()
1123
- 1000
1124
- >> > sys.setrecursionlimit(5000 )
1125
- ```
1126
-
1127
-
1128
1109
CSV
1129
1110
---
1130
1111
``` python
@@ -1633,7 +1614,7 @@ def get_border(screen):
1633
1614
from collections import namedtuple
1634
1615
P = namedtuple(' P' , ' x y' )
1635
1616
height, width = screen.getmaxyx()
1636
- return P(width - 1 , height - 1 )
1617
+ return P(width- 1 , height- 1 )
1637
1618
```
1638
1619
1639
1620
0 commit comments