From a13714809c02866ae0487564e44bf19877284c67 Mon Sep 17 00:00:00 2001 From: fprtmjinho Date: Wed, 8 Oct 2025 16:16:07 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=EC=BB=B4=ED=94=84=EB=A6=AC=ED=97=A8?= =?UTF-8?q?=EC=85=98=20=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/comprehension.py | 51 +++++++++++++++++++++++++++++++++++++++ chapter1/pythonic_code.md | 26 ++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 chapter1/comprehension.py create mode 100644 chapter1/pythonic_code.md diff --git a/chapter1/comprehension.py b/chapter1/comprehension.py new file mode 100644 index 0000000..d10734e --- /dev/null +++ b/chapter1/comprehension.py @@ -0,0 +1,51 @@ +################################################## +# 리스트 +# 기본 +# numbers = [] +# for i in range(5): +# numbers.append(i) +# 리스트 컴프리헨션 사용 +numbers = [i for i in range(5)] +print('numbers :',numbers) + +# 고급(중첩 루프) +# pairs = [] +# for x in range(3): +# for y in range(3): +# pairs.append((x,y)) +pairs = [(x, y) for x in range(3) for y in range(3)] +print('pairs :',pairs) + +# 고급(조건 및 중첩 루프) +# not_same_pairs = [] +# for x in range(3): +# for y in range(3): +# if x != y: +# not_same_pairs.append((x, y)) +not_same_pairs = [(x, y) for x in range(3) for y in range(3) if x != y] +print('not_same_pairs :', not_same_pairs) + +# 문자열 +# words = ['java', 'python', 'dart'] +# upper_words = [] +# for word in words: +# upper_words.append(word.upper()) +words = ['java', 'python', 'dart'] +upper_words = [word.upper() for word in words] +print('upper_words :',upper_words) + +################################################## +# 딕셔너리 +dic_numbers = {i : i for i in range(5)} +print(dic_numbers) +################################################## +################################################## +# 집합 +data = [1, 2, 2, 3, 4, 4] +set_numbers = {i for i in data} +print(set_numbers) +################################################## +# 제너레이터 +generator_numbers = {i for i in data} +print(list(generator_numbers)) +################################################## \ No newline at end of file diff --git a/chapter1/pythonic_code.md b/chapter1/pythonic_code.md new file mode 100644 index 0000000..024fe94 --- /dev/null +++ b/chapter1/pythonic_code.md @@ -0,0 +1,26 @@ +## 학습 내용 요약 + + + + +## 핵심 개념 + + + + +## 실습 예제 + + + + +## 참고 자료 + + + + +## 체크리스트 + +- [ ] 주제에 대한 핵심 내용을 다루고 있다 +- [ ] 실습 가능한 코드 예제가 포함되어 있다 +- [ ] 마크다운 문법이 올바르게 적용되었다 +- [ ] 참고 자료 출처가 명시되어 있다 From b05e18cff925b1e3247f3aac28aea4872e62aef0 Mon Sep 17 00:00:00 2001 From: fprtmjinho Date: Wed, 8 Oct 2025 17:08:13 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=EC=96=B8=ED=8C=A8=ED=82=B9=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/unpacking.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 chapter1/unpacking.py diff --git a/chapter1/unpacking.py b/chapter1/unpacking.py new file mode 100644 index 0000000..101aac4 --- /dev/null +++ b/chapter1/unpacking.py @@ -0,0 +1,24 @@ +# 기본 언패킹 +a, b, c = (10, 20, 30) +print(a, b, c) # 10 20 30 + +# 가변인자 언패킹 +x, *y, z = [1, 2, 3, 4, 5] +print(x, y, z) # 1 [2, 3, 4] 5 + +# 함수 호출 시 언패킹 +def f(p, q, r): + return p + q + r + +nums = (4, 5, 6) +print(f(*nums)) + +# 키워드 인자 언패킹 +d = {'p': 1, 'q': 2, 'r': 3} +print(f(**d)) # 6 + +# 딕셔너리 병합 언패킹 +d1 = {'a': 1, 'b': 2} +d2 = {'c': 3} +d_merged = {**d1, **d2} +print(d_merged) \ No newline at end of file From 6678c28642ccd3d39316f508b77ae2a643b79b3f Mon Sep 17 00:00:00 2001 From: fprtmjinho Date: Wed, 8 Oct 2025 17:08:18 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=EC=A0=9C=EB=84=88=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/generator.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 chapter1/generator.py diff --git a/chapter1/generator.py b/chapter1/generator.py new file mode 100644 index 0000000..c7c2920 --- /dev/null +++ b/chapter1/generator.py @@ -0,0 +1,18 @@ +def gen_range(start, stop): + while start < stop: + yield start + start += 1 +res = [i for i in gen_range(0, 10)] +print(res) + +def generator_send(): + main_routine_value = 0 + while True: + main_routine_value = yield + yield main_routine_value * 2 +gen = generator_send() +print(gen) +next(gen) +print(gen.send(100)) # 200 +next(gen) +print(gen.send(300)) # 600 \ No newline at end of file From 59e53ecca8fdae0af5c20e88544960209907e390 Mon Sep 17 00:00:00 2001 From: fprtmjinho Date: Wed, 8 Oct 2025 17:09:19 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=EB=A7=A4=EC=A7=81=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/magic_method.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 chapter1/magic_method.py diff --git a/chapter1/magic_method.py b/chapter1/magic_method.py new file mode 100644 index 0000000..e49c521 --- /dev/null +++ b/chapter1/magic_method.py @@ -0,0 +1,28 @@ +class Fruit(object): + def __init__(self, name, price): + self._name = name + self._price = price + + def __add__(self, target): + return self._price + target._price + + def __sub__(self, target): + return self._price - target._price + + def __mul__(self, target): + return self._price * target._price + + def __truediv__(self, target): + return self._price / target._price + + def __str__(self): + return self._name + +apple = Fruit("사과", 100000) +durian = Fruit("두리안", 50000) + +print(apple + durian) +print(apple - durian) +print(apple * durian) +print(apple / durian) +print(f"{apple}와 {durian}") \ No newline at end of file From ae537993d99f4b03270bc265715a069d181de47b Mon Sep 17 00:00:00 2001 From: fprtmjinho Date: Wed, 8 Oct 2025 18:47:09 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=EB=8D=B0=EC=BD=94=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=ED=84=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/decorator.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 chapter1/decorator.py diff --git a/chapter1/decorator.py b/chapter1/decorator.py new file mode 100644 index 0000000..4d44622 --- /dev/null +++ b/chapter1/decorator.py @@ -0,0 +1,17 @@ +def hello(): + print("hello") +def deco(fn): + def deco_hello(): + print("*" * 20) + fn() + print("*" * 20) + return deco_hello +@deco +def hello2(): + print("hello 2") +hello() +deco_hello = deco(hello) +deco_hello() +hello = deco(hello) +hello() +hello2() \ No newline at end of file From 79572f50f0c39a39aab18a4350e77bc2df9c294a Mon Sep 17 00:00:00 2001 From: fprtmjinho Date: Wed, 8 Oct 2025 18:51:02 +0900 Subject: [PATCH 6/6] =?UTF-8?q?readme=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/pythonic_code.md | 49 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/chapter1/pythonic_code.md b/chapter1/pythonic_code.md index 024fe94..5c3abc7 100644 --- a/chapter1/pythonic_code.md +++ b/chapter1/pythonic_code.md @@ -2,25 +2,66 @@ +- 제너레이터는 지연 평가 방식이 가능하기 때문에 객체에 엄청나게 많은 데이터를 넣어 생성해야 할 때에는 컴프리헨션보다 효율성 측면에서 매우 뛰어나다. +- 파이썬에서 존재하는 타입들은 모두 클래스이기 때문에 매직 메소드를 이용하여 연산이 가능하다. ## 핵심 개념 +#### 딕셔너리로 제너레이터 컴프리헨션 불가능하다. + +- 딕셔너리는 key value로 구성되어야 하기 때문 + +#### 언패킹은 함수에서 사용할때 주의해야함. + +- 인자를 해체하는 개념이기 때문에 해체된 인자의 개수가 함수의 인자 개수와 다르다 에러가 발생함 + +#### 제너레이터는 컴프리헨션보다 메모리 효울성이 좋다. + +- 제너레이터는 지연 평가 방식이 가능하기 때문에 메모리르 더 효율적으로 사용할 수 있다. + +#### 함수에 데코레이터 편하게 적용하려면 @를 사용하면된다. + +- @데코레이터함수 ## 실습 예제 +- 컴프리헨션 : comprehension.py +- 언패킹 : unpacking.py +- 제너레이터 : generator.py +- 매직메소드 : magic_method.py +- 데코레이터 : decorator.py ## 참고 자료 +#### 컴프리헨션 + +- https://incurio.tistory.com/entry/Python-리스트-컴프리헨션List-Comprehension-완벽-가이드?utm_source=chatgpt.com#google_vignette + +#### 언패킹 + +- https://ground90.tistory.com/131 + +#### 제너레이터 + +- https://velog.io/@jewon119/TIL30.-Python-제너레이터Generator-개념-정리 + +#### 매직메소드 + +- https://tibetsandfox.tistory.com/42 + +#### 데코레이터 + +- https://wikidocs.net/160127 ## 체크리스트 -- [ ] 주제에 대한 핵심 내용을 다루고 있다 -- [ ] 실습 가능한 코드 예제가 포함되어 있다 -- [ ] 마크다운 문법이 올바르게 적용되었다 -- [ ] 참고 자료 출처가 명시되어 있다 +- [x] 주제에 대한 핵심 내용을 다루고 있다 +- [x] 실습 가능한 코드 예제가 포함되어 있다 +- [x] 마크다운 문법이 올바르게 적용되었다 +- [x] 참고 자료 출처가 명시되어 있다