TIL122 ✨

YaR LabΒ·2023λ…„ 10μ›” 16일
0

TIL✨

λͺ©λ‘ 보기
101/135
post-thumbnail

πŸ—“οΈ23.10.10

πŸ“› set

with Python

  • Pythonμ—μ„œλŠ” set을 for문으둜 돌 λ•Œ set의 μš”μ†Œλ₯Ό μ œκ±°ν•˜λ©΄ set의 크기가 λ°”κ»΄μ„œ λŸ°νƒ€μž„ μ—λŸ¬κ°€ λ‚œλ‹€
  • RuntimeError: Set changed size during iteration
test = set()
test.add(1)
test.add(2)
test.add(3)
test.add(4)

for i in test:
    if i == 1:
        test.remove(3)
    print(i)
print(test)

with Swift

  • Swiftμ—μ„œλŠ” for문에 λ“€μ–΄κ°ˆλ•Œ μƒμˆ˜λ‘œ λ“€μ–΄κ°€κΈ° λ•Œλ¬Έμ— 도쀑에 setμš”μ†Œκ°€ remove돼도 였λ₯˜κ°€ λ‚˜μ§€ μ•ŠλŠ”λ‹€
var test = Set<Int>()
test.insert(1)
test.insert(2)
test.insert(3)
test.insert(4)
for i in test {
    if i == 1 {
        test.remove(3)
        test.remove(1)
    }
    print(i)
}
print(test)

0개의 λŒ“κΈ€