Skip to content

Writing Efficient Python Code

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Take Notes

Terminologies in Writting Efficient Code

  1. Efficient Code: It is any code that has best runtime or (small latency), uses minimal resource(avoid overhead), and follow pythonic code style.
  2. Pythonic Code: way of writing code in python that obeys the writing styles available.

Ways to Write Efficient Python Code

Use Python Standard Library tools: In order to make your code more efficient, it very important to use functions and objects that comes with python installation.

  • range() - it is used to generate sequence of numbers.
  • enumerate() - it used to create an index item pair for each item pair.
  • map() - it applies a function over an object

The Power of Numpy

Numpy helps us to respresent numeric data in a way that is very fast to querie and easy to manipulate. It is homogenous that it represent one particular data type. Numpy arrays allow us to easily apply functions to all elements without looping over them. That it makes it easy to treat a data variable as a single one.

Timing and Profiling Codes

# Add your code snippets here