Session Ready
Exercise

Using %timeit: your turn!

You'd like to create a list of integers from 0 to 50 using the range() function. However, you are unsure whether using list comprehension or unpacking the range object into a list is faster. Let's use %timeit to find the best implementation.

For your convenience, a reference table of time orders of magnitude is provided below (faster at the top).

symbol name unit (s)
ns nanosecond 10-9
µs (us) microsecond 10-6
ms millisecond 10-3
s second 100
Instructions 1/3
undefined XP
  • 1
  • 2
  • 3
  • Use list comprehension and range() to create a list of integers from 0 to 50 called nums_list_comp.