diff --git a/README.md b/README.md index bd1c655..0fcff82 100644 --- a/README.md +++ b/README.md @@ -28,21 +28,25 @@ if __name__ == '__main__': # Skips next line if file was imported. List ---- +```python + = [, , ...] # Creates new list. Also list(). +``` + ```python = [index] # First index is 0. Last -1. Allows assignments. - = [] # Or: [from_inclusive : to_exclusive : ±step] + = [] # Also [from_inclusive : to_exclusive : ±step]. ``` ```python -.append() # Or: += [] -.extend() # Or: += +.append() # Appends element to the end. Also += []. +.extend() # Appends elements to the end. Also += . ``` ```python -.sort() # Sorts in ascending order. +.sort() # Sorts elements in ascending order. .reverse() # Reverses the list in-place. - = sorted() # Returns a new sorted list. - = reversed() # Returns reversed iterator. + = sorted() # Returns new list with sorted elements. + = reversed() # Returns reversed iterator of elements. ``` ```python @@ -70,6 +74,10 @@ list_of_chars = list() Dictionary ---------- +```python + = {key_1: val_1, key_2: val_2, ...} # Use `[key]` to get or set the value. +``` + ```python = .keys() # Coll. of keys that reflects changes. = .values() # Coll. of values that reflects changes. @@ -101,17 +109,15 @@ value = .pop(key) # Removes item or raises KeyErro >>> from collections import Counter >>> counter = Counter(['blue', 'blue', 'blue', 'red', 'red']) >>> counter['yellow'] += 1 ->>> print(counter) -Counter({'blue': 3, 'red': 2, 'yellow': 1}) ->>> counter.most_common()[0] -('blue', 3) +>>> print(counter.most_common()) +[('blue', 3), ('red', 2), ('yellow', 1)] ``` Set --- ```python - = set() # `{}` returns a dictionary. + = {, , ...} # Use `set()` for empty set. ``` ```python diff --git a/index.html b/index.html index a5f7742..d28adf0 100644 --- a/index.html +++ b/index.html @@ -54,12 +54,12 @@
- +

Comprehensive Python Cheatsheet


#Contents

ToC = {
+
ToC = {
     '1. Collections': [List, Dictionary, Set, Tuple, Range, Enumerate, Iterator, Generator],
     '2. Types':       [Type, String, Regular_Exp, Format, Numbers, Combinatorics, Datetime],
     '3. Syntax':      [Args, Inline, Import, Decorator, Class, Duck_Types, Enum, Exception],
@@ -89,8 +89,7 @@
     '7. Libraries':   [Progress_Bar, Plot, Table, Console_App, GUI, Scraping, Web, Profile],
     '8. Multimedia':  [NumPy, Image, Animation, Audio, Synthesizer, Pygame, Pandas, Plotly]
 }
-
- + @@ -100,17 +99,19 @@ main() # Runs `def main(): ...` function. -

#List

<el>   = <list>[index]          # First index is 0. Last -1. Allows assignments.
-<list> = <list>[<slice>]        # Or: <list>[from_inclusive : to_exclusive : ±step]
+

#List

<list> = [<el_1>, <el_2>, ...]  # Creates new list. Also list(<collection>).
 
-
<list>.append(<el>)             # Or: <list> += [<el>]
-<list>.extend(<collection>)     # Or: <list> += <collection>
+
<el>   = <list>[index]          # First index is 0. Last -1. Allows assignments.
+<list> = <list>[<slice>]        # Also <list>[from_inclusive : to_exclusive : ±step].
 
-
<list>.sort()                   # Sorts in ascending order.
+
<list>.append(<el>)             # Appends element to the end. Also <list> += [<el>].
+<list>.extend(<collection>)     # Appends elements to the end. Also <list> += <coll>.
+
+
<list>.sort()                   # Sorts elements in ascending order.
 <list>.reverse()                # Reverses the list in-place.
-<list> = sorted(<collection>)   # Returns a new sorted list.
-<iter> = reversed(<list>)       # Returns reversed iterator.
+<list> = sorted(<collection>)   # Returns new list with sorted elements.
+<iter> = reversed(<list>)       # Returns reversed iterator of elements.
 
sum_of_elements  = sum(<collection>)
 elementwise_sum  = [sum(pair) for pair in zip(list_a, list_b)]
@@ -132,11 +133,13 @@ list_of_chars    = list(<str>)
 <list>.remove(<el>)             # Removes first occurrence of the item or raises ValueError.
 <list>.clear()                  # Removes all items. Also works on dictionary and set.
 
-

#Dictionary

<view> = <dict>.keys()                          # Coll. of keys that reflects changes.
-<view> = <dict>.values()                        # Coll. of values that reflects changes.
-<view> = <dict>.items()                         # Coll. of key-value tuples that reflects chgs.
+

#Dictionary

<dict> = {key_1: val_1, key_2: val_2, ...}      # Use `<dict>[key]` to get or set the value.
 
+
<view> = <dict>.keys()                          # Coll. of keys that reflects changes.
+<view> = <dict>.values()                        # Coll. of values that reflects changes.
+<view> = <dict>.items()                         # Coll. of key-value tuples that reflects chgs.
+
value  = <dict>.get(key, default=None)          # Returns default if key is missing.
 value  = <dict>.setdefault(key, default=None)   # Returns and writes default if key is missing.
 <dict> = collections.defaultdict(<type>)        # Returns a dict with default value `<type>()`.
@@ -154,13 +157,11 @@ value = <dict>.pop(key)                         

Counter

>>> from collections import Counter
 >>> counter = Counter(['blue', 'blue', 'blue', 'red', 'red'])
 >>> counter['yellow'] += 1
->>> print(counter)
-Counter({'blue': 3, 'red': 2, 'yellow': 1})
->>> counter.most_common()[0]
-('blue', 3)
+>>> print(counter.most_common())
+[('blue', 3), ('red', 2), ('yellow', 1)]
 
-

#Set

<set> = set()                                   # `{}` returns a dictionary.
+

#Set

<set> = {<el_1>, <el_2>, ...}                   # Use `set()` for empty set.
 
<set>.add(<el>)                                 # Or: <set> |= {<el>}
@@ -2928,7 +2929,7 @@ $ deactivate                # Deactivates the active
  
 
   
 
diff --git a/parse.js b/parse.js
index d1bd4c8..62c9514 100755
--- a/parse.js
+++ b/parse.js
@@ -30,9 +30,7 @@ const hljs = require('highlightjs');
 
 
 const TOC =
-  '
' + - '

Contents

\n' + - '
ToC = {\n' +
+  '
ToC = {\n' +
   '    \'1. Collections\': [List, Dictionary, Set, Tuple, Range, Enumerate, Iterator, Generator],\n' +
   '    \'2. Types\':       [Type, String, Regular_Exp, Format, Numbers, Combinatorics, Datetime],\n' +
   '    \'3. Syntax\':      [Args, Inline, Import, Decorator, Class, Duck_Types, Enum, Exception],\n' +
@@ -776,6 +774,7 @@ function insertLinks() {
 function unindentBanner() {
   const montyImg = $('img').first();
   montyImg.parent().addClass('banner');
+  montyImg.parent().css({"margin-bottom": "20px", "padding-bottom": "7px"})
   const downloadPraragrapth = $('p').first();
   downloadPraragrapth.addClass('banner');
 }