Python

re.sub('[^A-Za-z0-9-_ ]+', '', inp_string)
b = a
a[:] = [col.lower() for col in a]
print(b)
from itertools import combinations

list(combinations(range(4), 2)) # combinations(iterable, r) # n C r
# output [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
max(X_train, key=len) # key is a one argument function

student_tuples = [
     ('john', 'A', 15),
     ('jane', 'B', 12),
     ('dave', 'B', 10),
]

sorted(student_tuples, key=lambda student: student[2])   # sort by age
# output: [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

# using operator module in python to extend sorting features
from operator import itemgetter, attrgetter # attrgetter can be used to access named attributes of an instance (e.g. of a class)

sorted(student_tuples, key=itemgetter(2)) # sorting by the item at index 2
# output: [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

sorted(student_tuples, key=itemgetter(1,2)) # sorting by item at index 1 and then index 2
# output: [('john', 'A', 15), ('dave', 'B', 10), ('jane', 'B', 12)]

sorted(student_tuples, key=itemgetter(2), reverse=True)
# output: [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]

NumPy

x = np.arange(9)

x
# array([0, 1, 2, 3, 4, 5, 6, 7, 8])

y = x.reshape(3, 3)

y
# array([[0, 1, 2],
#        [3, 4, 5],
#        [6, 7, 8]])

y.base  # .reshape() creates a view
# array([0, 1, 2, 3, 4, 5, 6, 7, 8])

z = y[[2, 1]]

z
# array([[6, 7, 8],
#       [3, 4, 5]])

z.base is None  # advanced indexing creates a copy
# True
# np.allcose in an assert statement
assert np.allclose(avg, [0.1666667, 2.0]), "Debug the last example"