///
Search

set ๋ฉ”์„œ๋“œ๋“ค

๋ถ„๋ฅ˜
์ง‘ํ•ฉ
์ž๋ฃŒ๊ตฌ์กฐ
์†์„ฑ
์ƒ์„ฑ์ผ
2022/01/22 16:54
์ตœ์ข… ์ˆ˜์ •
2022/01/22 16:57

set ํŠน์ง•

โ€ข
์ค‘๋ณต ์—†์Œ
โ€ข
์ˆœ์„œ์—†์Œ(์ธ๋ฑ์Šค์—†์Œ)
โ€ข
์ •๋ ฌ๋ถˆ๊ฐ€
โ‡’ set ์„ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„๋กœ ์‚ฌ์šฉํ•˜๊ณ , ๋‹ค์‹œ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Œ

๊ต์ง‘ํ•ฉ,ํ•ฉ์ง‘ํ•ฉ,์ฐจ์ง‘ํ•ฉ

>>> s1 = set([1, 2, 3, 4, 5, 6]) >>> s2 = set([4, 5, 6, 7, 8, 9]) #1. ๊ต์ง‘ํ•ฉ & >>> s1 & s2 {4, 5, 6} #2. ํ•ฉ์ง‘ํ•ฉ | >>> s1 | s2 {1, 2, 3, 4, 5, 6, 7, 8, 9} #3. ์ฐจ์ง‘ํ•ฉ - >>> s1 - s2 {1, 2, 3} >>> s2 - s1 {8, 9, 7}
Python
๋ณต์‚ฌ

๋ฉ”์„œ๋“œ

๊ฐ’ 1๊ฐœ ์ถ”๊ฐ€(add)

>>> s1 = set([1, 2, 3]) >>> s1.add(4) >>> s1 {1, 2, 3, 4}
Python
๋ณต์‚ฌ

๊ฐ’ ์—ฌ๋Ÿฌ ๊ฐœ ์ถ”๊ฐ€(update)

>>> s1 = set([1, 2, 3]) >>> s1.update([4, 5, 6]) >>> s1 {1, 2, 3, 4, 5, 6}
Python
๋ณต์‚ฌ

ํŠน์ • ๊ฐ’ ์ œ๊ฑฐ(remove)

>>> s1 = set([1, 2, 3]) >>> s1.remove(2) >>> s1 {1, 3}
Python
๋ณต์‚ฌ