Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- FastAPI
- MDP
- 영상처리
- Got
- Flutter
- Computer Architecture
- fastapi를 사용한 파이썬 웹 개발
- Image Processing
- MATLAB
- ARM
- Algorithm
- ML
- BAEKJOON
- Widget
- llm을 활용 단어장 앱 개발일지
- 백준
- study book
- BFS
- 파이토치 트랜스포머를 활용한 자연어 처리와 컴퓨터비전 심층학습
- system hacking
- Dreamhack
- pytorch
- DART
- Kaggle
- C++
- BOF
- bloc
- rao
- Stream
- PCA
Archives
- Today
- Total
Bull
[python:syntax] zip 본문
의미
for문에서 쓰이며 여러 시퀀스를 동시에 순회한다.
예제가 더 이해하기 쉬우니 예제로 남길 것이다.
예제
1. 두 리스트를 함께 순회
list1 = [1, 2, 3]
list2 = ['a', 'b', 'c']
for item1, item2 in zip(list1, list2):
print(item1, item2)
1 a
2 b
3 c
2. 세 리스트를 함께 순회
list1 = [1, 2, 3]
list2 = ['a', 'b', 'c']
list3 = [10.1, 20.2, 30.3]
for item1, item2, item3 in zip(list1, list2, list3):
print(item1, item2, item3)
1 a 10.1
2 b 20.2
3 c 30.3
3. 리스트와 튜플을 함께 순회
list1 = [1, 2, 3]
tuple1 = ('x', 'y', 'z')
for item1, item2 in zip(list1, tuple1):
print(item1, item2)
1 x
2 y
3 z
4. zip을 통해 리스트를 컴프리헨션
list1 = [1, 2, 3]
list2 = [4, 5, 6]
zipped_list = [(x, y) for x, y in zip(list1, list2)]
print(zipped_list)
'Computer Language > Python' 카테고리의 다른 글
[Python] 유튜브 오디오 추출하기(.wav) (0) | 2024.05.26 |
---|---|
[python/lib:numpy] np.stack()과 np.comcatenate() (0) | 2024.04.18 |