@@ -96,7 +96,7 @@ value = <dict>.pop(key)                         # Removes item or raises KeyErro
9696### Counter  
9797``` python 
9898>> >  from  collections import  Counter
99- >> >  colors =  [' blue'  , ' red '  , ' blue'  , ' red'  , ' blue '  ]
99+ >> >  colors =  [' blue'  , ' blue '  , ' blue'  , ' red'  , ' red '  ]
100100>> >  counter =  Counter(colors)
101101>> >  counter[' yellow'  ] +=  1 
102102Counter({' blue'  : 3 , ' red'  : 2 , ' yellow'  : 1 })
@@ -377,7 +377,7 @@ import re
377377``` 
378378
379379### Special Sequences  
380- *  ** By default digits, whitespaces  and alphanumerics  from all alphabets are matched, unless ` 'flags=re.ASCII' `  argument is used.** 
380+ *  ** By default digits, alphanumerics  and whitespaces  from all alphabets are matched, unless ` 'flags=re.ASCII' `  argument is used.** 
381381*  ** Use a capital letter for negation.** 
382382``` python 
383383' \d'   ==  ' [0-9]'                                  #  Matches any digit.
@@ -442,7 +442,7 @@ Format
442442#### Comparison of presentation types:  
443443``` text 
444444+---------------+-----------------+-----------------+-----------------+-----------------+ 
445- |               |     {<real >}    |    {<real >:f}   |    {<real >:e}   |    {<real >:%}   | 
445+ |               |    {<float >}    |   {<float >:f}   |   {<float >:e}   |   {<float >:%}   | 
446446+---------------+-----------------+-----------------+-----------------+-----------------+ 
447447|   0.000056789 |    '5.6789e-05' |     '0.000057'  |  '5.678900e-05' |     '0.005679%' | 
448448|   0.00056789  |    '0.00056789' |     '0.000568'  |  '5.678900e-04' |     '0.056789%' | 
@@ -456,7 +456,7 @@ Format
456456``` 
457457``` text 
458458+---------------+-----------------+-----------------+-----------------+-----------------+ 
459- |               |   {<float>:.2}  |   {<real >:.2f}  |   {<real >:.2e}  |   {<real >:.2%}  | 
459+ |               |   {<float>:.2}  |  {<float >:.2f}  |  {<float >:.2e}  |  {<float >:.2%}  | 
460460+---------------+-----------------+-----------------+-----------------+-----------------+ 
461461|   0.000056789 |    '5.7e-05'    |       '0.00'    |    '5.68e-05'   |       '0.01%'   | 
462462|   0.00056789  |    '0.00057'    |       '0.00'    |    '5.68e-04'   |       '0.06%'   | 
@@ -541,7 +541,7 @@ shuffle(<list>)
541541Combinatorics
542542------------- 
543543*  ** Every function returns an iterator.** 
544- *  ** If you want to print the iterator, you need to pass it to the list() function!** 
544+ *  ** If you want to print the iterator, you need to pass it to the list() function first !** 
545545
546546``` python 
547547from  itertools import  product, combinations, combinations_with_replacement, permutations
@@ -1093,7 +1093,7 @@ class MyComparable:
10931093``` python 
10941094class  MyHashable :
10951095    def  __init__ (self  , a ):
1096-         self ._a =  copy.deepcopy(a) 
1096+         self ._a =  a 
10971097    @ property 
10981098    def  a (self  ):
10991099        return  self ._a
@@ -1146,7 +1146,7 @@ class Counter:
11461146``` 
11471147
11481148#### Python has many different iterator objects:  
1149- *  ** Objects  returned by the [ iter()] ( #iterator )  function, such as list\_ iterator and set\_ iterator.** 
1149+ *  ** Iterators  returned by the [ iter()] ( #iterator )  function, such as list\_ iterator and set\_ iterator.** 
11501150*  ** Objects returned by the [ itertools] ( #itertools )  module, such as count, repeat and cycle.** 
11511151*  ** Generators returned by the [ generator functions] ( #generator )  and [ generator expressions] ( #comprehension ) .** 
11521152*  ** File objects returned by the [ open()] ( #open )  function, etc.** 
@@ -1170,7 +1170,7 @@ class Counter:
11701170``` 
11711171
11721172### Context Manager  
1173- *  ** Enter() should lock the resources and ( optionally)  return an object.** 
1173+ *  ** Enter() should lock the resources and optionally return an object.** 
11741174*  ** Exit() should release the resources.** 
11751175*  ** Any exception that happens inside the with block is passed to the exit() method.** 
11761176*  ** If it wishes to suppress the exception it must return a true value.**  
@@ -1205,8 +1205,9 @@ class MyIterable:
12051205    def  __init__ (self  , a ):
12061206        self .a =  a
12071207    def  __iter__ (self  ):
1208-         for  el in  self .a:
1209-             yield  el
1208+         return  iter (self .a)
1209+     def  __contains__ (self  , el ):
1210+         return  el in  self .a
12101211``` 
12111212
12121213``` python 
@@ -1336,7 +1337,7 @@ from functools import partial
13361337LogicOp =  Enum(' LogicOp'  , {' AND'  : partial(lambda  l , r : l and  r),
13371338                           ' OR'   : partial(lambda  l , r : l or  r)})
13381339``` 
1339- *  ** Another solution in this particular case is to use built-in functions ` 'and_' `  and ` 'or_' `  from the module [ operator] ( #operator ) .** 
1340+ *  ** Another solution in this particular case is to use built-in functions and \_ ()  and or \_ ()  from the module [ operator] ( #operator ) .** 
13401341
13411342
13421343Exceptions
@@ -1419,7 +1420,7 @@ BaseException
14191420      +-- StopIteration           # Raised by next() when run on an empty iterator. 
14201421      +-- TypeError               # Raised when an argument is of wrong type. 
14211422      +-- ValueError              # When an argument is of right type but inappropriate value. 
1422-            +-- UnicodeError       # Raised when encoding/decoding strings from/to  bytes fails. 
1423+            +-- UnicodeError       # Raised when encoding/decoding strings to/from  bytes fails. 
14231424``` 
14241425
14251426#### Collections and their exceptions:  
@@ -1589,7 +1590,7 @@ from glob import glob
15891590``` 
15901591
15911592``` python 
1592- < str >   =  getcwd()                   #  Returns current working directory.
1593+ < str >   =  getcwd()                   #  Returns the  current working directory.
15931594< str >   =  path.join(< path> , ... )     #  Joins two or more pathname components.
15941595< str >   =  path.abspath(< path> )       #  Returns absolute path.
15951596``` 
@@ -1663,15 +1664,15 @@ from pathlib import Path
16631664OS Commands
16641665----------- 
16651666### Files and Directories  
1666- *  ** Paths can be either strings, Paths,  or DirEntry objects.** 
1667+ *  ** Paths can be either strings, Paths or DirEntry objects.** 
16671668*  ** Functions report OS related errors by raising either OSError or one of its [ subclasses] ( #exceptions-1 ) .** 
16681669
16691670``` python 
16701671import  os, shutil
16711672``` 
16721673
16731674``` python 
1674- os.chdir(< path> )                    #  Changes current working directory.
1675+ os.chdir(< path> )                    #  Changes the  current working directory.
16751676os.mkdir(< path> , mode = 0o 777 )        #  Creates a directory. Mode is in octal.
16761677``` 
16771678
@@ -1787,7 +1788,7 @@ import csv
17871788< writer> .writerow(< collection> )     #  Encodes objects using `str(<el>)`.
17881789< writer> .writerows(< coll_of_coll> )  #  Appends multiple rows.
17891790``` 
1790- *  ** File must be opened with ` 'newline=""' `  argument, or an extra '\r' will be added to every '\n' on platforms that use '\r\n' linendings !** 
1791+ *  ** File must be opened with ` 'newline=""' `  argument, or an extra '\r' will be added to every '\n' on platforms that use '\r\n' line endings !** 
17911792
17921793### Parameters  
17931794*  ** ` 'dialect' `  - Master parameter that sets the default values.** 
@@ -1846,9 +1847,9 @@ db.close()
18461847### Read  
18471848** Returned values can be of type str, int, float, bytes or None.** 
18481849``` python 
1849- < cursor>  =  db.execute(' <query>'  )                #  Can raise  sqlite3.OperationalError .
1850+ < cursor>  =  db.execute(' <query>'  )                #  Raises a subclass of  sqlite3.Error .
18501851< tuple >   =  < cursor> .fetchone()                  #  Returns next row. Also next(<cursor>).
1851- < list >    =  < cursor> .fetchall()                  #  Returns remaining rows.
1852+ < list >    =  < cursor> .fetchall()                  #  Returns remaining rows. Also list(<cursor>). 
18521853``` 
18531854
18541855### Write  
@@ -1889,7 +1890,7 @@ db.executemany('<query>', <coll_of_above>)      # Runs execute() many times.
18891890from  mysql import  connector
18901891db =  connector.connect(host = < str > , user = < str > , password = < str > , database = < str > )
18911892< cursor>  =  db.cursor()
1892- < cursor> .execute(' <query>'  )                     #  Only cursor has execute method .
1893+ < cursor> .execute(' <query>'  )                     #  Raises a subclass of mysql.connector.Error .
18931894< cursor> .execute(' <query>'  , < list / tuple > )       #  Replaces '%s's in query with values.
18941895< cursor> .execute(' <query>'  , < dict / namedtuple> )  #  Replaces '%(<key>)s's with values.
18951896``` 
@@ -1958,7 +1959,7 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03'
19581959``` 
19591960
19601961### Format  
1961- #### For standard sizes start format string with:  
1962+ #### For standard type  sizes start format string with:  
19621963*  ** ` '=' `  - native byte order** 
19631964*  ** ` '<' `  - little-endian** 
19641965*  ** ` '>' `  - big-endian (also ` '!' ` )** 
@@ -1982,8 +1983,9 @@ Array
19821983
19831984``` python 
19841985from  array import  array
1985- < array>  =  array(' <typecode>'  , < collection> )    #  Array from coll.  of numbers.
1986+ < array>  =  array(' <typecode>'  , < collection> )    #  Array from collection  of numbers.
19861987< array>  =  array(' <typecode>'  , < bytes > )         #  Array from bytes object.
1988+ < array>  =  array(' <typecode>'  , < array> )         #  Treats array as a sequence of numbers.
19871989< bytes >  =  bytes (< array> )                       #  Or: <array>.tobytes()
19881990``` 
19891991
0 commit comments