Using %timeit: formal name or literal syntax
Python allows you to create data structures using either a formal name or a literal syntax. In this exercise, you'll explore how using a literal syntax for creating a data structure can speed up runtimes.
data structure | formal name | literal syntax |
---|---|---|
list | list() |
[] |
dictionary | dict() |
{} |
tuple | tuple() |
() |
This exercise is part of the course
Writing Efficient Python Code
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a list using the formal name
formal_list = ____
print(formal_list)
# Create a list using the literal syntax
literal_list = ____
print(literal_list)