Learn

Congratulations on completing this module on functional programming in Python. We’ve covered many topics on how to write neat and efficient solutions using functional programming. Let’s briefly recap everything covered so far:

  • Functional programming follows the declarative approach to programming; the programmer describes what needs to be done as opposed to how it is done.
  • Functional programming relies heavily on immutable data structures.
  • It is preferable to use a tuple instead of a list when writing code because a tuple is immutable.
  • Using a namedtuple to store data leads to a more readable data structure.
  • The namedtuple collection resides in the collections library.
  • A namedtuple is created like so:
    name = ("name", ["property1", "property2", …, "property"])
  • Representing an object by a namedtuple is done like so:
    obj = name(property1, property2, …, property)
  • Referencing an element of a namedtuple is done like this:
    property = name.property
  • A lambda function is an anonymous function.
  • A lambda function can be stored in a variable like any other data type.
  • A lambda function can be defined directly while passing it as an argument of another function.
  • The three higher-order functions Python provides are:
    • map()
    • filter()
    • reduce()
  • These functions can be supplied as the iterable parameter to any of the higher-order functions. Ex:
    • h = map(lambda, filter(lambda, map(lambda, iterable)))
  • Combining map() and filter() filters an iterable before a mapping function is applied.
  • Combining reduce() and filter() filters an iterable before it is reduced.
  • A CSV file can be processed by supplying the CSV reader as the iterable to the higher-order functions.
  • A JSON file can only be represented in Python by a dictionary.
  • An iterable is not available to read data stored in a JSON file.
  • A dictionary must be provided to the higher-order functions when processing a JSON file.

Happy Coding!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?