From 47f3ee69d9fd8fb9c7cf1d018182bd835d7da42d Mon Sep 17 00:00:00 2001 From: Vasyl Smutok Date: Thu, 24 Oct 2024 20:51:24 +0300 Subject: [PATCH 1/2] Update checklist.md to prefer generator expressions Replace the guideline on avoiding `for` loops with a detailed example explaining the preference for generator expressions. This change aims to clarify best practices by providing both good and bad examples of summing processed items in a collection. --- checklist.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/checklist.md b/checklist.md index ef619686..c4037ef6 100644 --- a/checklist.md +++ b/checklist.md @@ -1,4 +1,6 @@ # Сheck Your Code Against the Following Points +___ + ## Make Code Easier 1. Don't use an extra `else` statement. @@ -20,8 +22,23 @@ else: return "Is not hungry!" ``` -2. Use a `@staticmethod` for some functions. -3. Don't use a `for` loop if you can use a list comprehension. +2. Don't use a `for` loop if you can use or generator expression. + +Good example: + +```python +return sum(item.process() for item in collection) +``` + +Bad example: + +```python +total = 0 +for item in collection: + total += item.process() +return total +``` +___ ## Code Style From 07d6f596ec3429ce44193fc71217cb7cd47aa1b2 Mon Sep 17 00:00:00 2001 From: Vasyl Smutok Date: Fri, 25 Oct 2024 12:18:57 +0300 Subject: [PATCH 2/2] Fix typo and remove unnecessary lines Corrected a typo in the checklist item regarding loop usage. Also, removed some redundant separator lines to enhance readability. --- checklist.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/checklist.md b/checklist.md index c4037ef6..87362d3d 100644 --- a/checklist.md +++ b/checklist.md @@ -1,5 +1,4 @@ # Сheck Your Code Against the Following Points -___ ## Make Code Easier @@ -22,7 +21,7 @@ else: return "Is not hungry!" ``` -2. Don't use a `for` loop if you can use or generator expression. +2. Don't use a `for` loop if you can use generator expression. Good example: @@ -38,7 +37,6 @@ for item in collection: total += item.process() return total ``` -___ ## Code Style