@@ -599,7 +599,7 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary
599
599
```
600
600
* ** Use ` '<D/DT>.weekday()' ` to get the day of the week (Mon == 0).**
601
601
* ** ` 'fold=1' ` means the second pass in case of time jumping back for one hour.**
602
- * ** ` '<DTa> = resolve_imaginary(<DTa>)' ` fixes DTs that fall into missing hour.**
602
+ * ** ` '<DTa> = resolve_imaginary(<DTa>)' ` fixes DTs that fall into the missing hour.**
603
603
604
604
### Now
605
605
``` python
@@ -731,10 +731,10 @@ def f(x, *args, z, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3
731
731
732
732
### Other Uses
733
733
``` python
734
- < list > = [* < collection> [, ... ]]
735
- < set > = {* < collection> [, ... ]}
736
- < tuple > = (* < collection> , [... ])
737
- < dict > = {** < dict > [, ... ]}
734
+ < list > = [* < collection> [, ... ]]
735
+ < set > = {* < collection> [, ... ]}
736
+ < tup. > = (* < collection> , [... ])
737
+ < dict > = {** < dict > [, ... ]}
738
738
```
739
739
740
740
``` python
@@ -746,48 +746,40 @@ Inline
746
746
------
747
747
### Lambda
748
748
``` python
749
- < function > = lambda : < return_value>
750
- < function > = lambda <argument_1 >, <argument_2 >: < return_value>
749
+ < func > = lambda : < return_value>
750
+ < func > = lambda <arg_1 >, <arg_2 >: < return_value>
751
751
```
752
752
753
753
### Comprehensions
754
754
``` python
755
- < list > = [i+ 1 for i in range (10 )] # [1, 2, ..., 10]
756
- < set > = {i for i in range (10 ) if i > 5 } # {6, 7, 8, 9}
757
- < iter > = (i+ 5 for i in range (10 )) # (5, 6, ..., 14)
758
- < dict > = {i: i* 2 for i in range (10 )} # {0: 0, 1: 2, ..., 9: 18}
755
+ < list > = [i+ 1 for i in range (10 )] # [1, 2, ..., 10]
756
+ < set > = {i for i in range (10 ) if i > 5 } # {6, 7, 8, 9}
757
+ < iter > = (i+ 5 for i in range (10 )) # (5, 6, ..., 14)
758
+ < dict > = {i: i* 2 for i in range (10 )} # {0: 0, 1: 2, ..., 9: 18}
759
759
```
760
760
761
761
``` python
762
- out = [i+ j for i in range (10 ) for j in range (10 )]
763
- ```
764
-
765
- #### Is the same as:
766
- ``` python
767
- out = []
768
- for i in range (10 ):
769
- for j in range (10 ):
770
- out.append(i+ j)
762
+ >> > [l+ r for l in ' abc' for r in ' abc' ]
763
+ [' aa' , ' ab' , ' ac' , ... , ' cc' ]
771
764
```
772
765
773
766
### Map, Filter, Reduce
774
767
``` python
775
- from functools import reduce
776
-
777
- < iter > = map (lambda x : x + 1 , range (10 )) # (1, 2, ..., 10)
778
- < iter > = filter (lambda x : x > 5 , range (10 )) # (6, 7, 8, 9)
779
- < obj> = reduce (lambda out , x : out + x, range (10 )) # 45
768
+ < iter > = map (lambda x : x + 1 , range (10 )) # (1, 2, ..., 10)
769
+ < iter > = filter (lambda x : x > 5 , range (10 )) # (6, 7, 8, 9)
770
+ < obj> = reduce (lambda out , x : out + x, range (10 )) # 45
780
771
```
772
+ * ** Reduce must be imported from functools module.**
781
773
782
774
### Any, All
783
775
``` python
784
- < bool > = any (< collection> ) # False if empty.
785
- < bool > = all (el[1 ] for el in < collection> ) # True if empty.
776
+ < bool > = any (< collection> ) # False if empty.
777
+ < bool > = all (el[1 ] for el in < collection> ) # True if empty.
786
778
```
787
779
788
- ### If - Else
780
+ ### Conditional Expression
789
781
``` python
790
- < obj> = < expression_if_true > if < condition> else < expression_if_false >
782
+ < obj> = < exp_if_true > if < condition> else < exp_if_false >
791
783
```
792
784
793
785
``` python
@@ -810,7 +802,7 @@ direction = Direction.n
810
802
811
803
``` python
812
804
from dataclasses import make_dataclass
813
- Creature = make_dataclass(' Creature' , [' location ' , ' direction ' ])
805
+ Creature = make_dataclass(' Creature' , [' loc ' , ' dir ' ])
814
806
creature = Creature(Point(0 , 0 ), Direction.n)
815
807
```
816
808
@@ -1950,13 +1942,14 @@ Struct
1950
1942
1951
1943
``` python
1952
1944
from struct import pack, unpack, iter_unpack
1945
+ ```
1953
1946
1947
+ ``` python
1954
1948
< bytes > = pack(' <format>' , < num_1> [, < num_2> , ... ])
1955
1949
< tuple > = unpack(' <format>' , < bytes > )
1956
1950
< tuples> = iter_unpack(' <format>' , < bytes > )
1957
1951
```
1958
1952
1959
- ### Example
1960
1953
``` python
1961
1954
>> > pack(' >hhl' , 1 , 2 , 3 )
1962
1955
b ' \x00\x01\x00\x02\x00\x00\x00\x03 '
@@ -2049,6 +2042,7 @@ Threading
2049
2042
* ** That is why using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.**
2050
2043
``` python
2051
2044
from threading import Thread, RLock, Semaphore, Event, Barrier
2045
+ from concurrent.futures import ThreadPoolExecutor
2052
2046
```
2053
2047
2054
2048
### Thread
@@ -2084,10 +2078,6 @@ with lock:
2084
2078
2085
2079
### Thread Pool Executor
2086
2080
** Object that manages thread execution.**
2087
- ``` python
2088
- from concurrent.futures import ThreadPoolExecutor
2089
- ```
2090
-
2091
2081
``` python
2092
2082
< Exec> = ThreadPoolExecutor(max_workers = None ) # Or: `with ThreadPoolExecutor() as <name>: …`
2093
2083
< Exec> .shutdown(wait = True ) # Blocks until all threads finish executing.
0 commit comments