Python

Documentation
pydoc3 -b
Running Time
import time
start_time = time.time()
code...
t = time.time() - start_time
print("Total Elapsed Time of Running Program: {:.2f} seconds.".format(t))
Default Argument
import sys

if 2 == len(sys.argv):
    file_name = sys.argv[1]
else:
    file_name = '/home/aavloni/Desktop/Python_II/trees.dat'
Sort By Key
def second(obj):
  return obj[1]

x.sort(key=second)
Identity vs Equality
Identity: a is b
Equality: a == b
Show ID: hex(id(b))
Immutable (int, strings, etc...) assignment through '=' Aliases
Mutable (lists, etc...) assignment through '=' Copies
Copying Lists
creates an alias
new_list = existing_list
creates a new list*
new_list = list(existing_list)
creates a new list*
new_list = existing_list[:]

* only works on single dimension lists
Get / Change Type of Object
type(a)
list(a)
isinstance(a, (float, int))
Sort in place vs Sort as copy
In place: list_name.sort()
As copy: sorted(list_name)
Generic Exception
try:
    something()
except Exception as e:
len vs sizeof()
len returns number of elements
sys.sizeof() returns number of bytes
Tuple Benefits
Saves memory with multiple identical objects because of immutability.
Can be used as dictionary keys (hashable because tuples are immutable).
Can be used to unpack things, eg. a,b = b,a
Can be used to create a function with variable number of arguments:
def fn(*args)