.. _consider-using-generator: consider-using-generator / R1728 ================================ **Message emitted:** ``Consider using a generator instead '%s(%s)'`` **Description:** *If your container can be large using a generator will bring better performance.* **Problematic code:** .. literalinclude:: /data/messages/c/consider-using-generator/bad.py :language: python **Correct code:** .. literalinclude:: /data/messages/c/consider-using-generator/good.py :language: python **Additional details:** Removing ``[]`` inside calls that can use containers or generators should be considered for performance reasons since a generator will have an upfront cost to pay. The performance will be better if you are working with long lists or sets. For ``max``, ``min`` and ``sum`` using a generator is also recommended by pep289. **Related links:** - `PEP 289 `_ - `Benchmark and discussion for any/all/list/tuple `_ - `Benchmark and discussion for sum/max/min `_ Created by the `refactoring `__ checker.