- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: python-best-practices/no-range-loop-with-len
Language: Python
Severity: Error
Category: Best Practices
Do not iterate over an array using for in range(len(array))
. Use instead for i in array
.
import random
import string
DEFAULT_CHAR_STRING = string.ascii_lowercase + string.digits
def generate_random_string(chars=DEFAULT_CHAR_STRING, size=20):
return "".join(random.choice(chars) for _ in range(size))
NORMALIZED_SIZE = 8
def normalize(s):
builder = []
for i in range(NORMALIZED_SIZE):
builder.append(s[i].capitalize())
return "".join(builder)
FORBIDDEN_WORDS = set(["bad1", "bad2"])
def filter_forbidden_tags(tags):
for i in range(len(tags)):
if tags[i].tag in FORBIDDEN_WORDS:
del tags[i]
return tags
for i in range(len(tab)): # iterate directly over the array
bla(tab[i])
for i in range(len(tab)): # iterate directly over the array
bla(tab[i])
for i in range(len(tab)): # iterate directly over the array
tab[i] = bla
for i, _ in enumerate(lst):
print(i)
for i in range(len(lst)):
print(i)
plop = tab[i]
for i in tab:
bla(i)
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products