these notes are based on the awesome repository by Chip Huyen on some Python tips and Tricks.

Lambdas

  • Lambda keyword used to create inline functions.
 
square_ld = lambda x: x * x
 
  • Quick declaration makes lambda function ideal for use in callbacks and when functions are to be passed as arguments to other functions.

Map

  • map(fn,iterable) applies the fn to all elements of the iterable and returns a map object.
  • Can also use map with more than one iterable. Eg: if we want to calculate the mean squared error of a simple linear function f(x) = ax + b , with the true label labels, the methods are equivalent.