728x90
728x90
iterable1 = 'ABCD'
iterable2 = 'xy'
iterable3 = '1234'
for i in iterable1:
for j in iterable2:
for k in iterable3:
print(i+j+k)
a, b, c, d
x, y
1, 2, 3, 4
์ ์์ค์ฝ๋๋ 3๊ฐ์ ๋ฆฌ์คํธ์ ๊ฐ ์์์ ๋ํด ๊ณฑ์งํฉ์ ๊ตฌํ๋ ์์ค์ฝ๋์ด๋ค.
ax1, ax2, ... , cy3, cy4, ... , dy4
์์ ๊ฐ์ด ๋ชจ๋ ๊ฒฝ์ฐ๋ฅผ ๊ตฌํ๋ ค๋ฉด 3์ค ๋ฐ๋ณต๋ฌธ์ ํตํด ํด๊ฒฐ์ด ๊ฐ๋ฅํ๋ค. ํ์ง๋ง, ํผํฌ๋จผ์ค ์ธก๋ฉด์์ ์ข์ง ์์ ๋ฟ๋๋ฌ ์์ค์ฝ๋์ ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง ์ ์๋ค.
import itertools
iterable1 = 'ABCD'
iterable2 = 'xy'
iterable3 = '1234'
itertools.product(iterable1, iterable2, iterable3)
itertools.product๋ฅผ ์ฌ์ฉํ๋ฉด ๋ชจ๋ ๊ฒฝ์ฐ์ ์ ๋๋ ๊ณฑ์งํฉ์ ๊ตฌํ ์ ์๋ค.
728x90
๋ฐ์ํ