ποΈ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)