%timeit を使う:正式名称かリテラル記法か
Python では、データ構造を「正式名称」か「リテラル記法」のいずれかで作成できます。この演習では、データ構造の作成にリテラル記法を使うと実行時間を短縮できることを確認します。
| data structure | formal name | literal syntax |
|---|---|---|
| list | list() |
[] |
| dictionary | dict() |
{} |
| tuple | tuple() |
() |
この演習はコースの一部です
効率的なPythonコードの書き方
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create a list using the formal name
formal_list = ____
print(formal_list)
# Create a list using the literal syntax
literal_list = ____
print(literal_list)