# listreference

x in s
x not in s
s + t         the concatenation of s and t
s * n, n * s  equivalent to adding s to itself n times
s[i]
s[i:j]
s[i:j:k]
s[i] = x
s[i:j] = t    slice of s from i to j is replaced by the contents of the iterable t
del s[i:j]    same as s[i:j] = []
s[i:j:k] = t  the elements of s[i:j:k] are replaced by those of t
del s[i:j:k]  removes the elements of s[i:j:k] from the list
s *= n        updates s with its contents repeated n times
len(s)
min(s)
max(s)

L.append(object)
L.count(value) -> integer
L.extend(iterable)
L.index(value, [start, [stop]]) -> integer  return first index of value; ValueError on failure
L.insert(index, object)                     insert object before index
L.pop([index]) -> item                      remove and return item at index (default last); IndexError on failure
L.remove(value)                             remove first occurrence of value; ValueError on failure
L.reverse()                                 reverse *IN PLACE*
L.sort(cmp=None, key=None, reverse=False)   stable sort *IN PLACE*; cmp(x, y) -> -1, 0, 1

# Set local variables in list comprehension howto

• Use nested list comprehension
oddsq = [y for y in (x ** 2 for x in [1, 2, 3]) if y % 2 == 1]
print(oddsq)
[1, 9]
f1 = lambda x: 2*x
f2 = lambda x: x*x
print([f(x) for x in range(5) for f in (f1,f2)])
[0, 0, 2, 1, 4, 4, 6, 9, 8, 16]