Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions INSEA-99/week02/10798_세로읽기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
from itertools import zip_longest
input = sys.stdin.readline

lines = [input().rstrip() for _ in range(5)]
vertical_chars = [''.join(filter(None, chars)) for chars in zip_longest(*lines)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 이 방법 사용해서 복습해봐야겠어요!

print(''.join(vertical_chars))


# - filter(function, iterable)
# iterable의 각 요소를 차례로 function에 넣고 반환값이 True면 사용, False면 제거
# function 대산 None을 넣는 경우 None을 제거해줌

# - zip
# 여러 iterable(리스트, 문자열 등) 을 병렬로 묶어서 튜플을 만들어줌
# 가장 짧은 iterable 길이에 맞춰 묶음이 생성됨
# 예시)
# a = [1, 2, 3]
# b = ['x', 'y']
# zip(a, b) -> [(1, 'x'), (2, 'y')]
#
# - zip_longest
# zip과 기능이 동일하지만 가장 긴 iterable 길이에 맞추고 그것보다 짧은 iterable은 None으로 채움(None 대신 다른 값으로 설정 가능. 인자에 fillvalue=?)

# - * (언패킹)
# 리스트, 튜플, 문자열 등 iterable을 개별 요소로 풀어서 함수 인자나 다른 자료구조에 전달
# ex)
# lst1 = [1, 2]
# lst2 = [3, 4]
# combined = [*lst1, *lst2] # [1, 2, 3, 4]
16 changes: 16 additions & 0 deletions INSEA-99/week02/10807_개수_세기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys
input = sys.stdin.readline

ans = 0

# 입력
input() # 다른 언어는 리스트 입력 받을 때 몇개인지 정보가 필요한 경우가 있는데, 파이썬은 필요없어서 그냥 받기만 하고 사용 안함
nums = map(int, input().split())
v = int(input())

# 풀이
for n in nums:
if(n==v): ans+=1

# 출력
print(ans)
16 changes: 16 additions & 0 deletions INSEA-99/week02/10952_A+B-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys
input = sys.stdin.readline

while(True):
a, b = map(int, input().split())
if(a==0 and b==0):
break
print(a+b)

# [입력 받는 로직 설명]
# a, b = map(int, input().split())
# 예시) 만약 "1 1" 입력이 들어왔다면
# 1. input()을 통해 "1 1"을 가져옴
# 2. input().split()를 통해 공백을 기준으로 쪼갠 리스트를 얻음["1", "1"] (쪼개는 기준 split에 인자 줘서 바꿀 수 있음)
# 3. map을 통해 list의 원소마다 int를 적용시켜줌 -> [1, 1]
# 4. a, b = [1, 1]를 하면 파이썬에서 제공하는 시퀀스 언패킹 기능으로 a=1, b=1이 할당됨
Loading