๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[์ด๊ฒ์ด ์ฝ๋ฉ ํ ์คํธ๋ค with Python]_11_์์ฃผ ์ฌ์ฉ๋๋ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ณธ๋ฌธ
[์ด๊ฒ์ด ์ฝ๋ฉ ํ ์คํธ๋ค with Python]_11_์์ฃผ ์ฌ์ฉ๋๋ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์ง์ง์ํ์นด 2022. 1. 29. 00:16220129 ์์ฑ
<๋ณธ ๋ธ๋ก๊ทธ๋ ใ์ด๊ฒ์ด ์ทจ์ ์ ์ํ ์ฝ๋ฉ ํ ์คํธ๋คใ ์ youtube๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค>
https://www.youtube.com/watch?v=W1SO2e5IaSo&list=PLVsNizTWUw7H9_of5YCB0FmsSc-K44y81&index=11
1. ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- ๋ด์ฅ ํจ์ : ๊ธฐ๋ณธ ์ ์ถ๋ ฅ ~ ์ ๋ ฌ ํจ์
- itertools : ๋ฐ๋ณต๋๋ ํํ์ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ( ์์ด, ์กฐํฉ )
- heapq : ํ (heap) ์๋ฃ๊ตฌ์กฐ (์ฐ์ ์์ ํ ๊ธฐ๋ฅ )
- bisect : ์ด์ง ํ์ ๊ธฐ๋ฅ
- collection : ๋ฑ(deque), ์นด์ดํฐ(counter)
- math : ์ํ์ ๊ธฐ๋ฅ (ํฉํ ๋ฆฌ์ผ, ์ ๊ณฑ๊ทผ, ์ต๋๊ณต์ฝ์, ์ผ๊ฐํจ์, ํ์ด)
sum([2,3,4,5])
min(3,4,5)
max(3,4,5)
eval(3,4,5)
sorted([3,4,2,3])
sorted([3,4,2,3], reverse = True)
sorted([3,4,2,3], key = list[1], reverse = True)
2. ์์ด๊ณผ ์กฐํฉ
- ์์ด
: ์๋ก ๋ค๋ฅธ n ๊ฐ์์ ์๋ก ๋ค๋ฅธ r ๊ฐ ์ ํํ์ฌ ์ผ๋ ฌ๋ก ๋์ด
from itertools import permutations
data = ["A", "B", "C"]
list(permutations(data, 3))
- ์กฐํฉ
: ์๋ก ๋ค๋ฅธ n ๊ฐ์์ ์์์ ์๊ด ์์ด ์๋ก ๋ค๋ฅธ r ๊ฐ ์ ํ
from itertools import conbinations
data = ["A", "B", "C"]
list(conbinations(data, 3))
3. ์ค๋ณต ์์ด๊ณผ ์ค๋ณต ์กฐํฉ
- ์ค๋ณต์์ด
from itertools import product
data = ["A", "B", "C"]
list(product(data, repeat = 2))
- ์ค๋ณต์กฐํฉ
from itertools import combinations_with_replacement
data = ["A", "B", "C"]
list(combinations_with_replacement(data, 2))
4. counter
: ๋ฑ์ฅ ํ์ ์ธ๊ธฐ
: ๋ฐ๋ณต ๊ฐ๋ฅํ ๊ฐ์ฒด๊ฐ ์ฃผ์ด์ก์ ๋ ๋ด๋ถ์ ์์๊ฐ ๋ช๋ฒ์ฉ ๋ฑ์ฅํ๋์ง ํ์ธ
5. ์ต๋๊ณต์ฝ์, ์ต์๊ณต๋ฐฐ์
- ์ต๋๊ณต์ฝ์
import math
dec lcm(a, b):
return a * b // math.gcd(a, b)
a = 32
b = 12
print(math.gcd(a,b))
- ์ต์๊ณต๋ฐฐ์
import math
dec lcm(a, b):
return a * b // math.gcd(a, b)
a = 32
b = 12
print(lcm(a, b))