.. _use-dict-literal: use-dict-literal / R1735 ======================== **Message emitted:** ``Consider using '%s' instead of a call to 'dict'.`` **Description:** *Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.* **Problematic code:** ``empty_dict.py``: .. literalinclude:: /data/messages/u/use-dict-literal/bad/empty_dict.py :language: python ``init_dict_from_another.py``: .. literalinclude:: /data/messages/u/use-dict-literal/bad/init_dict_from_another.py :language: python ``init_with_keyword.py``: .. literalinclude:: /data/messages/u/use-dict-literal/bad/init_with_keyword.py :language: python **Correct code:** ``empty_dict.py``: .. literalinclude:: /data/messages/u/use-dict-literal/good/empty_dict.py :language: python ``init_dict_from_another.py``: .. literalinclude:: /data/messages/u/use-dict-literal/good/init_dict_from_another.py :language: python ``init_with_litteral.py``: .. literalinclude:: /data/messages/u/use-dict-literal/good/init_with_litteral.py :language: python **Additional details:** https://gist.github.com/hofrob/ad143aaa84c096f42489c2520a3875f9 This example script shows an 18% increase in performance when using a literal over the constructor in python version 3.10.6. **Related links:** - `Performance Analysis of Python’s dict() vs dict literal `_ Created by the `refactoring `__ checker.