Head vs breakz
[Code] - Python / zip() 사용법 본문
zip()
자료형을 묶어서 사용가능하게 하는 함수이다. 여러개의 자료형을 묶어서 사용 할 수 있다.
color = ['yellow','dark','blue','green']
num_1 = [1,2,3,4]
txt = ['노랑','블랙','파랑','초록']
#예시
list_color = list(zip(color,num_1,txt))
#결과
print(list_color)
[('yellow', 1, '노랑'), ('dark', 2, '블랙'), ('blue', 3, '파랑'), ('green', 4, '초록')]
color = ['yellow','dark','blue','green']
num_2 = [1,2,3,4,5,6]
#예시
list_color_1 = list(zip(color,num_2))
#결과
print(list_color_1)
[('yellow', 1), ('dark', 2), ('blue', 3), ('green', 4)]
자료의 길이가 동일하지 않을 때, 최소한의 길이만 사용된다.
phone_number = ['01132231321','0103265131','0106893265','01069531111']
country =['korea','korea','usa','china']
for i in zip(country,phone_number):
print(i)
('korea', '01132231321')
('korea', '0103265131')
('usa', '0106893265')
('china', '01069531111')
phone_number = ['01132231321','0103265131','0106893265','01069531111']
country =['korea','korea','usa','china']
for i,j in zip(country,phone_number):
print(i+':'+j)
korea:01132231321
korea:0103265131
usa:0106893265
china:01069531111
'Head > Code' 카테고리의 다른 글
[Code] - Python / heapq, deque (0) | 2020.11.03 |
---|---|
[Code] - Python / rjust(), ljust() , center(), zfill() 사용법 (0) | 2020.09.01 |
[Code] - Python / 순열 Permutation , 조합 Combination, 곱집합 Product 사용법 (0) | 2020.08.26 |
[Code] - Python / lambda, map, reduce, filter 사용법 (0) | 2020.08.25 |
[CODE] - ImageDataGenerator (0) | 2020.07.15 |