๋ฐ์ํ
250x250
Notice
Recent Posts
- Today
- Total
๋ชฉ๋กํ์ด์ฌ ์์ ๊ฐ์ (1)
DATA101
์๋ ํ์ธ์, ์ค๋์ ํ์ด์ฌ Counter ํจ์๋ฅผ ํ์ฉํ์ฌ ๋ฆฌ์คํธ ๋ด ์์ ๊ฐ์๋ฅผ ๊ตฌํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์๊ฐํด ๋๋ฆฝ๋๋ค. ์์ค์ฝ๋ from collections import Counter # ๊ณผ์ผ ์ ๋ณด๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ ์์ฑ arr = ['Apple', 'Banana', 'Orange', 'Apple', 'Grape', 'Orange', 'Water Melon'] cnt = Counter(arr) print(cnt['Apple']) # ์ฌ๊ณผ ๊ฐ์ print(cnt['Orange']) # ์ค๋ ์ง ๊ฐ์ print(dict(cnt)) # ๋์ ๋๋ฆฌ ์๋ฃํ์ผ๋ก ์ถ๋ ฅ ๊ฐ์ฅ ๋จผ์ , ๋ฆฌ์คํธ ๋ด ์์์ ๊ฐ์๋ฅผ ์ธ๊ธฐ ์ํด์๋ collections ํ์ด์ฌ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ Counter ํจ์๋ฅผ ๊ฐ์ ธ์์ผ ํฉ๋๋ค. ํด๋น ํจ์์ ๋ฆฌ..
SW ๊ฐ๋ฐ/Python
2021. 4. 23. 11:29