MulaiMulai sekarang secara gratis

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

Latihan ini adalah bagian dari kursus

Writing Efficient Python Code

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create a list of integers (0-50) using list comprehension
nums_list_comp = [num for num in ____(____)]
print(nums_list_comp)
Edit dan Jalankan Kode