Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I understand that they are both essentially the same thing but in terms of style, which is the better (more Pythonic) one to use to create an empty list or dict?

1 Answer

0 votes
by (106k points)

If you are looking for the speed then there is no competition for empty lists/dicts see the code below:-

>>> from timeit import timeit 

>>> timeit("[]") 

0.040084982867934334 

>>> timeit("list()") 

0.17704233359267718 

>>> timeit("{}") 

0.033620194745424214 

>>> timeit("dict()") 

0.1821558326547077

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)

Browse Categories

...