December 2018
Beginner to intermediate
796 pages
19h 54m
English
Coders sometimes don't see the point in writing a function with a body of one or two lines of code, so let's look at an example that shows you why you should do it.
Imagine that you need to multiply two matrices:

Would you prefer to have to read this code:
# matrix.multiplication.nofunc.pya = [[1, 2], [3, 4]]b = [[5, 1], [2, 1]]c = [[sum(i * j for i, j in zip(r, c)) for c in zip(*b)] for r in a]
Or would you prefer this one:
# matrix.multiplication.func.py# this function could also be defined in another moduledef matrix_mul(a, b): return [[sum(i * j for i, j in zip(r, c)) for c in zip(*b)] for r in a]a = [[1, 2], [3, ...Read now
Unlock full access