diff --git a/README.md b/README.md index 4692faf..47d39a8 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ flatter_list = list(itertools.chain.from_iterable()) product_of_elems = functools.reduce(lambda out, x: out * x, ) list_of_chars = list() ``` +* **Check out module [operator](#operator) for alternative versions of examples.** ```python = .count() # Returns number of occurrences. Also works on strings. @@ -2112,10 +2113,10 @@ from operator import itemgetter, attrgetter, methodcaller ```python import operator as op -product_of_elems = functools.reduce(op.mul, ) elementwise_sum = map(op.add, list_a, list_b) sorted_by_second = sorted(, key=op.itemgetter(1)) sorted_by_both = sorted(, key=op.itemgetter(1, 0)) +product_of_elems = functools.reduce(op.mul, ) LogicOp = enum.Enum('LogicOp', {'AND': op.and_, 'OR' : op.or_}) last_el = op.methodcaller('pop')() ``` @@ -2127,7 +2128,7 @@ Introspection ### Variables ```python - = dir() # Returns names of local variables (including functions). + = dir() # Returns names of local variables (incl. functions). = vars() # Returns dict of local variables. Also locals(). = globals() # Returns dict of global variables. ``` @@ -2135,7 +2136,7 @@ Introspection ### Attributes ```python = dir() # Returns names of object's attributes (incl. methods). - = vars() # Returns dict of object's fields. Also .__dict__. + = vars() # Returns dict of object's fields. Also .__dict__. ``` ```python diff --git a/index.html b/index.html index 136268a..5a92f55 100644 --- a/index.html +++ b/index.html @@ -249,6 +249,9 @@ flatter_list = list(itertools.chain.from_iterable(<list>)) product_of_elems = functools.reduce(lambda out, x: out * x, <collection>) list_of_chars = list(<str>) +
    +
  • Check out module operator for alternative versions of examples.
  • +
<int> = <list>.count(<el>)     # Returns number of occurrences. Also works on strings.
 index = <list>.index(<el>)     # Returns index of first occurrence or raises ValueError.
 <list>.insert(index, <el>)     # Inserts item at index and moves the rest to the right.
@@ -1853,14 +1856,14 @@ lock.release()
 
 
 
import operator as op
-product_of_elems = functools.reduce(op.mul, <collection>)
 elementwise_sum  = map(op.add, list_a, list_b)
 sorted_by_second = sorted(<collection>, key=op.itemgetter(1))
 sorted_by_both   = sorted(<collection>, key=op.itemgetter(1, 0))
+product_of_elems = functools.reduce(op.mul, <collection>)
 LogicOp          = enum.Enum('LogicOp', {'AND': op.and_, 'OR' : op.or_})
 last_el          = op.methodcaller('pop')(<list>)
 
-

#Introspection

Inspecting code at runtime.

Variables

<list> = dir()                       # Returns names of local variables (including functions).
+

#Introspection

Inspecting code at runtime.

Variables

<list> = dir()                       # Returns names of local variables (incl. functions).
 <dict> = vars()                      # Returns dict of local variables. Also locals().
 <dict> = globals()                   # Returns dict of global variables.
 
@@ -1868,7 +1871,7 @@ last_el = op.methodcaller('pop')(<l

Attributes

<list> = dir(<object>)               # Returns names of object's attributes (incl. methods).
-<dict> = vars(<object>)              # Returns dict of object's fields. Also <object>.__dict__.
+<dict> = vars(<object>)              # Returns dict of object's fields. Also <obj>.__dict__.
 
<bool> = hasattr(<object>, '<attr_name>')