Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

## 2024-05-24 - Optimize list comprehensions with walrus operator
**Learning:** List comprehensions with redundant function calls (like `input_str.find(char)`) cause the function to be evaluated twice, which is an anti-pattern that slows down processing, especially for O(n) string scanning.
**Action:** Use the Python 3.8+ walrus operator (`:=`) to compute and bind the result once, e.g., `[idx for char in chars if (idx := input_str.find(char)) != -1]`.
2 changes: 1 addition & 1 deletion helpers/dirty_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,5 @@ def _peek(self, n):

def get_start_pos(self, input_str: str) -> int:
chars = ["{", "[", '"']
indices = [input_str.find(char) for char in chars if input_str.find(char) != -1]
indices = [idx for char in chars if (idx := input_str.find(char)) != -1]
return min(indices) if indices else 0