Skip to content

Commit 6d4aa97

Browse files
committed
Small updates
1 parent fad0ada commit 6d4aa97

File tree

1 file changed

+28
-47
lines changed

1 file changed

+28
-47
lines changed

README.md

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -390,32 +390,14 @@ Numbers
390390
<real> = round(<real>, ±ndigits)
391391
```
392392

393-
### Constants
393+
### Math
394394
```python
395395
from math import e, pi
396-
```
397-
398-
### Trigonometry
399-
```python
400396
from math import cos, acos, sin, asin, tan, atan, degrees, radians
401-
```
402-
403-
### Logarithm
404-
```python
405397
from math import log, log10, log2
406-
<float> = log(<real> [, base]) # Base e, if not specified.
407-
```
408-
409-
### Infinity, nan
410-
```python
411398
from math import inf, nan, isinf, isnan
412399
```
413400

414-
#### Or:
415-
```python
416-
float('inf'), float('nan')
417-
```
418-
419401
### Statistics
420402
```python
421403
from statistics import mean, median, variance, pvariance, pstdev
@@ -444,19 +426,27 @@ from itertools import product, combinations, combinations_with_replacement, perm
444426
>>> product([0, 1], repeat=3)
445427
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1),
446428
(1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
429+
```
447430

431+
```python
448432
>>> product('ab', '12')
449433
[('a', '1'), ('a', '2'),
450434
('b', '1'), ('b', '2')]
435+
```
451436

437+
```python
452438
>>> combinations('abc', 2)
453439
[('a', 'b'), ('a', 'c'), ('b', 'c')]
440+
```
454441

442+
```python
455443
>>> combinations_with_replacement('abc', 2)
456444
[('a', 'a'), ('a', 'b'), ('a', 'c'),
457445
('b', 'b'), ('b', 'c'),
458446
('c', 'c')]
447+
```
459448

449+
```python
460450
>>> permutations('abc', 2)
461451
[('a', 'b'), ('a', 'c'),
462452
('b', 'a'), ('b', 'c'),
@@ -469,9 +459,9 @@ Datetime
469459
```python
470460
from datetime import datetime
471461
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'
475465
<datetime> = datetime.strptime('2015-05-12 00:39', '%Y-%m-%d %H:%M')
476466
```
477467

@@ -520,7 +510,7 @@ def add(*a):
520510
6
521511
```
522512

523-
#### Legal argument combinations with calls:
513+
#### Legal argument combinations:
524514
```python
525515
def f(*args): # f(1, 2, 3)
526516
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
542532

543533
### Other Uses
544534
```python
545-
>>> a = (1, 2, 3)
546-
>>> [*a]
547-
[1, 2, 3]
535+
<list> = [*<collection> [, ...]]
536+
<set> = {*<collection> [, ...]}
537+
<tuple> = (*<collection>, [...])
538+
<dict> = {**<dict> [, ...]}
548539
```
549540

550541
```python
551-
>>> head, *body, tail = [1, 2, 3, 4]
552-
>>> body
553-
[2, 3]
542+
head, *body, tail = <collection>
554543
```
555544

556545

@@ -566,8 +555,8 @@ Inline
566555
```python
567556
<list> = [i+1 for i in range(10)] # [1, 2, ..., 10]
568557
<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}
570558
<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}
571560
```
572561

573562
```python
@@ -665,11 +654,11 @@ from functools import partial
665654

666655
```python
667656
def get_counter():
668-
a = 0
657+
i = 0
669658
def out():
670-
nonlocal a
671-
a += 1
672-
return a
659+
nonlocal i
660+
i += 1
661+
return i
673662
return out
674663
```
675664

@@ -721,6 +710,8 @@ def fib(n):
721710
return n if n < 2 else fib(n-2) + fib(n-1)
722711
```
723712

713+
* **Recursion depth is limited to 1000 by default. To increase it use `'sys.setrecursionlimit(<depth>)'`.**
714+
724715
### Parametrized Decorator
725716
```python
726717
from functools import wraps
@@ -839,8 +830,8 @@ class Counter:
839830
```
840831

841832
```python
842-
>>> c = Counter()
843-
>>> c(), c(), c()
833+
>>> counter = Counter()
834+
>>> counter(), counter(), counter()
844835
(1, 2, 3)
845836
```
846837

@@ -1115,16 +1106,6 @@ b'.\n..\nfile1.txt\nfile2.txt\n'
11151106
```
11161107

11171108

1118-
Recursion Limit
1119-
---------------
1120-
```python
1121-
>>> import sys
1122-
>>> sys.getrecursionlimit()
1123-
1000
1124-
>>> sys.setrecursionlimit(5000)
1125-
```
1126-
1127-
11281109
CSV
11291110
---
11301111
```python
@@ -1633,7 +1614,7 @@ def get_border(screen):
16331614
from collections import namedtuple
16341615
P = namedtuple('P', 'x y')
16351616
height, width = screen.getmaxyx()
1636-
return P(width - 1, height - 1)
1617+
return P(width-1, height-1)
16371618
```
16381619

16391620

0 commit comments

Comments
 (0)