# zip()ํจ์๋ ๋ค๋ฅธ ๊ทธ๋ฃน์ ๋ฐ์ดํฐ๋ฅผ ์๋ก ์ฎ์ด์ค
# zip()ํจ์๋ ์ฌ๋ฌ๊ฐ์ ์ํ๊ฐ๋ฅํ(iterable) ๊ฐ์ฒด๋ฅผ input์ผ๋ก ๋ฐ์
# ์์๋๋ก ์ง์ ์ง์ด ํํ์ ํํ๋ก ์ ๊ทผํ ์ ์๋ ๋ฐ๋ณต์(iterator)๋ฅผ return
nums = [1, 2, 3, 4]
letters = ['a', 'b', 'c']
for pair in zip(nums, letters):
print(pair)
#(1, 'a')
#(2, 'b')
#(3, 'c')
nums = [1, 2, 3, 4]
letters_1 = ['A', 'B', 'C', 'D']
letters_2 = ['a', 'b', 'c', 'd']
for pair in zip(nums, letters_1, letters_2):
print(pair)
#(1, 'A', 'a')
#(2, 'B', 'b')
#(3, 'C', 'c')
#(4, 'D', 'd')
# ๋ฌธ์์ด์ด input์ผ ๊ฒฝ์ฐ
for pair in zip('1234', 'ABCD', 'abcd'):
print(pair)
#('1', 'A', 'a')
#('2', 'B', 'b')
#('3', 'C', 'c')
#('4', 'D', 'd')
# ์ฎ์ด๋์ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ํด์ (unzip)
# unpacking ์ฐ์ฐ์ * ๋ถ์ฌ์ ๋ค์ zip() ํจ์์ input
pairs = list(zip('1234', 'ABCD'))
print(pairs) #[('1', 'A'), ('2', 'B'), ('3', 'C'), ('4', 'D')]
nums, letters = zip(*pairs)
print(nums) #('1', '2', '3', '4')
print(letters) #('A', 'B', 'C', 'D')
#zip()ํ ๊ฐ์ฒด๋ฅผ dictํํ๋ก ๋ณํ
nums = [1, 2, 3]
letters = ['A', 'B', 'C']
print(dict(zip(nums, letters)))
#{1: 'A', 2: 'B', 3: 'C'}
#๊ธธ์ด๊ฐ ์๋ง์ ๊ฒฝ์ฐ => ์งง์๊ฑธ ๊ธฐ์ค์ผ๋ก ์์ฑํ๊ณ ๋๋จธ์ง๋ ๋ฒ๋ฆผ
numbers = ["1", "2", "3"]
letters = ['A']
print(list(zip(numbers, letters)))
# ('1', 'A')]
arr = ['1234', '1234', '1234', '1234']
print(list(zip(*arr)))
#[('1', '1', '1', '1'), ('2', '2', '2', '2'), ('3', '3', '3', '3'), ('4', '4', '4', '4')]
arr2 = [[1,2,3,4], [1,2,3,4], [1,2,3,4], [1,2,3,4]]
print(list(zip(*arr2)))
#[(1, 1, 1, 1), (2, 2, 2, 2), (3, 3, 3, 3), (4, 4, 4, 4)]