- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- ci
- containers
- csm
- ndm
- otel_guides
- overview
- slos
- synthetics
- tests
- 워크플로
ID: python-best-practices/collection-while-iterating
언어: 파이썬(Python)
**심각도:**오류
범주: 오류 가능성
딕셔너리에서 반복하는 동안 딕셔너리를 업데이트하지 마세요. 딕셔너리를 업데이트하려면 기존 값에서 새 딕셔너리를 생성하세요.
i = 0
for element in my_list:
my_list["stuff"] = i # modifying a dictionary while iterating
i += 1
i = 0
new_list = {}
for element in my_list:
new_list["stuff"] = i # putting value to a new dictionary
i += 1