Python

simple web server

python -m SimpleHTTPServer [port]

parse json

curl http://api.joind.in | python -mjson.tool

lists

list comprehenson

int_list = [i for i in range(100)]

generators

generator comprehenson

csv_gen = (row for row in open(file))

yield - will result in a generator object

generator functions - use yield instead of return

When the Python yield statement is hit, the programs suspends function execution and returns the yield value to the caller.When a function is suspended, the state of that function is saved`.

Tenary operator

syntax

[on_true] if [expression] else [on_false]

example

def find_max(a,b):
    return a if (a>b) else b

example

a,b=20,10
max = a if a > b else b
#max = 20

Number representation with underscore

num = 1_0_0_0_0
#num = 10000

Lambda - small anonymous function

x = lambda a : a + 10
print(x(5))