@@ -308,7 +308,7 @@ String
308
308
``` python
309
309
< list > = < str > .split() # Splits on one or more whitespace characters.
310
310
< list > = < str > .split(sep = None , maxsplit = - 1 ) # Splits on 'sep' str at most 'maxsplit' times.
311
- < list > = < str > .splitlines(keepends = False ) # Splits on \n,\r,\r\n. Keeps them if 'keepends '.
311
+ < list > = < str > .splitlines(keepends = False ) # Splits on [\n\r\f\v\x1c\x1d\x1e\x85] and '\r\n '.
312
312
< str > = < str > .join(< coll_of_strings> ) # Joins elements using string as a separator.
313
313
```
314
314
@@ -376,12 +376,13 @@ import re
376
376
```
377
377
378
378
### Special Sequences
379
- * ** By default digits, alphanumerics and whitespaces from all alphabets are matched, unless ` 'flags=re.ASCII' ` argument is used.**
379
+ * ** By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless ` 'flags=re.ASCII' ` argument is used.**
380
+ * ** As shown below, it restricts special sequence matches to ` '[\x00-\x7f]' ` and prevents ` '\s' ` from accepting ` '[\x1c\x1d\x1e\x1f]' ` .**
380
381
* ** Use a capital letter for negation.**
381
382
``` python
382
- ' \d' == ' [0-9]' # Matches any digit .
383
- ' \w' == ' [a-zA-Z0-9_]' # Matches any alphanumeric .
384
- ' \s' == ' [ \t\n\r\f\v ]' # Matches any whitespace .
383
+ ' \d' == ' [0-9]' # Matches decimal characters .
384
+ ' \w' == ' [a-zA-Z0-9_]' # Matches alphanumerics and underscore .
385
+ ' \s' == ' [ \t\n\r\f\v ]' # Matches whitespaces .
385
386
```
386
387
387
388
@@ -440,33 +441,32 @@ Format
440
441
441
442
#### Comparison of presentation types:
442
443
``` text
443
- +---------------+-----------------+-----------------+-----------------+-----------------+
444
- | | {<float>} | {<float>:f} | {<float>:e} | {<float>:%} |
445
- +---------------+-----------------+-----------------+-----------------+-----------------+
446
- | 0.000056789 | '5.6789e-05' | '0.000057' | '5.678900e-05' | '0.005679%' |
447
- | 0.00056789 | '0.00056789' | '0.000568' | '5.678900e-04' | '0.056789%' |
448
- | 0.0056789 | '0.0056789' | '0.005679' | '5.678900e-03' | '0.567890%' |
449
- | 0.056789 | '0.056789' | '0.056789' | '5.678900e-02' | '5.678900%' |
450
- | 0.56789 | '0.56789' | '0.567890' | '5.678900e-01' | '56.789000%' |
451
- | 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' |
452
- | 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' |
453
- | 567.89 | '567.89' | '567.890000' | '5.678900e+02' | '56789.000000%' |
454
- +---------------+-----------------+-----------------+-----------------+-----------------+
444
+ +--------------+----------------+----------------+----------------+----------------+
445
+ | | {<float>} | {<float>:f} | {<float>:e} | {<float>:%} |
446
+ +--------------+----------------+----------------+----------------+----------------+
447
+ | 0.000056789 | '5.6789e-05' | '0.000057' | '5.678900e-05' | '0.005679%' |
448
+ | 0.00056789 | '0.00056789' | '0.000568' | '5.678900e-04' | '0.056789%' |
449
+ | 0.0056789 | '0.0056789' | '0.005679' | '5.678900e-03' | '0.567890%' |
450
+ | 0.056789 | '0.056789' | '0.056789' | '5.678900e-02' | '5.678900%' |
451
+ | 0.56789 | '0.56789' | '0.567890' | '5.678900e-01' | '56.789000%' |
452
+ | 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' |
453
+ | 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' |
454
+ +--------------+----------------+----------------+----------------+----------------+
455
455
```
456
456
``` text
457
- +--------------- +----------------- +----------------- +-----------------+- ----------------+
458
- | | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |
459
- +--------------- +----------------- +----------------- +-----------------+- ----------------+
460
- | 0.000056789 | '5.7e-05' | '0.00' | '5.68e-05' | '0.01%' |
461
- | 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' |
462
- | 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' |
463
- | 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' |
464
- | 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' |
465
- | 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' |
466
- | 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' |
467
- | 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
468
- +---------------+-----------------+-----------------+-----------------+-----------------+
469
- ```
457
+ +--------------+----------------+----------------+----------------+ ----------------+
458
+ | | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |
459
+ +--------------+----------------+----------------+----------------+ ----------------+
460
+ | 0.000056789 | '5.7e-05' | '0.00' | '5.68e-05' | '0.01%' |
461
+ | 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' |
462
+ | 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' |
463
+ | 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' |
464
+ | 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' |
465
+ | 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' |
466
+ | 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' |
467
+ +--------------+----------------+----------------+----------------+----------------+
468
+ ```
469
+ * ** When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. That makes ` '{6.5:.0f}' ` a ` '6' ` and ` '{7.5:.0f}' ` an ` '8' ` . **
470
470
471
471
### Ints
472
472
``` python
@@ -1140,7 +1140,7 @@ class Counter:
1140
1140
```
1141
1141
1142
1142
#### Python has many different iterator objects:
1143
- * ** Iterators returned by the [ iter()] ( #iterator ) function, such as list\_ iterator and set\_ iterator.**
1143
+ * ** Sequence iterators returned by the [ iter()] ( #iterator ) function, such as list\_ iterator and set\_ iterator.**
1144
1144
* ** Objects returned by the [ itertools] ( #itertools ) module, such as count, repeat and cycle.**
1145
1145
* ** Generators returned by the [ generator functions] ( #generator ) and [ generator expressions] ( #comprehensions ) .**
1146
1146
* ** File objects returned by the [ open()] ( #open ) function, etc.**
@@ -2506,7 +2506,7 @@ def odds_handler(sport):
2506
2506
# $ pip3 install requests
2507
2507
>> > import threading, requests
2508
2508
>> > threading.Thread(target = run, daemon = True ).start()
2509
- >> > url = ' http://localhost:8080/odds/football'
2509
+ >> > url = ' http://localhost:8080/odds/football'
2510
2510
>> > data = {' team' : ' arsenal f.c.' }
2511
2511
>> > response = requests.post(url, data = data)
2512
2512
>> > response.json()
@@ -2899,7 +2899,7 @@ get_pause = lambda seconds: repeat(0, int(seconds * F))
2899
2899
sin_f = lambda i , hz : math.sin(i * 2 * math.pi * hz / F)
2900
2900
get_wave = lambda hz , seconds : (sin_f(i, hz) for i in range (int (seconds * F)))
2901
2901
get_hz = lambda key : 8.176 * 2 ** (int (key) / 12 )
2902
- parse_note = lambda note : (get_hz(note[:- 1 ]), 1 / 4 if ' ♩' in note else 1 / 8 )
2902
+ parse_note = lambda note : (get_hz(note[:2 ]), 1 / 4 if ' ♩' in note else 1 / 8 )
2903
2903
get_samples = lambda note : get_wave(* parse_note(note)) if note else get_pause(1 / 8 )
2904
2904
samples_f = chain.from_iterable(get_samples(n) for n in f ' { P1}{ P1}{ P2} ' .split(' ,' ))
2905
2905
samples_b = b ' ' .join(struct.pack(' <h' , int (f * 30000 )) for f in samples_f)
@@ -2957,14 +2957,14 @@ while all(event.type != pg.QUIT for event in pg.event.get()):
2957
2957
```
2958
2958
2959
2959
``` python
2960
- from pygame.transform import *
2960
+ from pygame.transform import scale, …
2961
2961
< Surf> = scale(< Surf> , (width, height)) # Returns scaled surface.
2962
2962
< Surf> = rotate(< Surf> , degrees) # Returns rotated and scaled surface.
2963
2963
< Surf> = flip(< Surf> , x_bool, y_bool) # Returns flipped surface.
2964
2964
```
2965
2965
2966
2966
``` python
2967
- from pygame.draw import *
2967
+ from pygame.draw import line, arc, rect
2968
2968
line(< Surf> , color, (x1, y1), (x2, y2), width) # Draws a line to the surface.
2969
2969
arc(< Surf> , color, < Rect> , from_rad, to_rad) # Also: ellipse(<Surf>, color, <Rect>)
2970
2970
rect(< Surf> , color, < Rect> ) # Also: polygon(<Surf>, color, points)
@@ -3029,12 +3029,12 @@ def update_speed(mario, tiles, pressed):
3029
3029
mario.spd = P(* [max (- limit, min (limit, s)) for limit, s in zip (MAX_SPEED , P(x, y))])
3030
3030
3031
3031
def update_position (mario , tiles ):
3032
- p = mario.rect.topleft
3033
- larger_speed = max (abs (s) for s in mario.spd)
3034
- for _ in range (larger_speed ):
3032
+ x, y = mario.rect.topleft
3033
+ n_steps = max (abs (s) for s in mario.spd)
3034
+ for _ in range (n_steps ):
3035
3035
mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))
3036
- p = P( * [a + s / larger_speed for a, s in zip (p, mario.spd)])
3037
- mario.rect.topleft = p
3036
+ x, y = x + mario.spd.x / n_steps, y + mario.spd.y / n_steps
3037
+ mario.rect.topleft = x, y
3038
3038
3039
3039
def get_boundaries (rect , tiles ):
3040
3040
deltas = {D.n: P(0 , - 1 ), D.e: P(1 , 0 ), D.s: P(0 , 1 ), D.w: P(- 1 , 0 )}
0 commit comments