From bc7bebe7f8837bc2db078cdf39ba020fe22a0b68 Mon Sep 17 00:00:00 2001 From: "deepsource-dev-autofix[bot]" <61578317+deepsource-dev-autofix[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 13:47:24 +0000 Subject: [PATCH] refactor: replace range(len(...)) with enumerate(...) Using `range(len(...))` is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators. Python has a built-in method `enumerate` which adds a counter to an iterable. --- demo_code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo_code.py b/demo_code.py index 7aa77bb31..d689c935d 100644 --- a/demo_code.py +++ b/demo_code.py @@ -132,7 +132,7 @@ def wrong_callable(): if __name__ == "__main__": args = ["--disable", "all"] - for i in range(len(args)): - has_truthy = bool(args[i]) + for i, item in enumerate(args): + has_truthy = bool(item) if has_truthy: break