Skip to content

Conversation

@echeniquegrecia
Copy link

When you use a for loop, on every iteration, you have to look up the variable holding
the list and then call its append() function. A list comprehension can be faster
than a for loop because it’s optimized for performance by Python’s internal mechanisms.

References:

@echeniquegrecia echeniquegrecia force-pushed the test branch 2 times, most recently from 86b0d88 to c116177 Compare May 21, 2025 08:51
@MP-Aubay MP-Aubay changed the title Team TREE 2025 - For loop vs list comprehension GCI12000 [Team TREE][2025] - For loop vs list comprehension May 21, 2025
MP-Aubay
MP-Aubay previously approved these changes May 21, 2025
Copy link
Contributor

@MP-Aubay MP-Aubay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me

@MP-Aubay MP-Aubay added the 👀 👀 review done 👀 👀 review done - waiting for changes label May 21, 2025
"creedengo",
"eco-design",
"performance",
"comprehension",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete tags "comprehension", "loop", and "iteration" because there aren't thematic tags but code centric

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks !

@@ -0,0 +1,18 @@
{
"title": "To use list comprehension instead for loop in simple iterations",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the "To" please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks !

CHANGELOG.md Outdated

### Added

- Added rule GCI1200: Detect a for loop and suggest a list comprehension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add here a link to current PR like done in other example in CHANGELOG.md

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

RULES.md Outdated
| | Resize images browser-side | Do not resize images using the HEIGHT and WIDTH attributes of the HTML code. This approach requires transferring these images to their original size, wasting bandwidth and CPU cycles. | [cnumr best practices (3rd edition) BP_034](https://github.com/cnumr/best-practices/blob/main/chapters/BP_034_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚀 |
| | Modify the DOM when traversing it | Modifying the DOM (Document Object Model) as you traverse it can lead to situations where the loop becomes very resource-intensive, especially CPU cycles. | [cnumr best practices (3rd edition) BP_041](https://github.com/cnumr/best-practices/blob/main/chapters/BP_041_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚫 |
| | Edit DOM elements to make it invisible | When an element of the Document Object Model (DOM) needs to be modified by several properties, each change in style or content will generate a repaint or reflow. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | 🚫 | 🚫 |
| GSI1200 | To use list comprehension instead for loop in simple iterations | | ||| 🚀 |||||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo error : GCI and not GSI, please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2025

This PR has been automatically marked as stale because it has no activity for 60 days.
Please add a comment if you want to keep the issue open. Thank you for your contributions!

@github-actions github-actions bot added the stale label Aug 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants