range(len(args))
with enumerate(args)
159
160if __name__ == "__main__":
161 args = ["--disable" "all"]
162 for i in range(len(args)):163 has_truthy = True if args[i] else False
164 if has_truthy:
165 break
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.
Using this, you can access the counter and the value from the iterable at the same time.
It is therefore recommended to replace range(len(...))
with enumerate(...)
.
for index in range(len(mylist)):
...
for index, element in enumerate(mylist):
...