-
Notifications
You must be signed in to change notification settings - Fork 3
Session1/fprtmjinho #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fprtmjinho
wants to merge
6
commits into
main
Choose a base branch
from
session1/fprtmjinho
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
| ################################################## |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| ## 학습 내용 요약 | ||
|
|
||
| <!-- 이번 주차에서 학습한 내용을 3-5줄로 요약해주세요 --> | ||
|
|
||
| - 제너레이터는 지연 평가 방식이 가능하기 때문에 객체에 엄청나게 많은 데이터를 넣어 생성해야 할 때에는 컴프리헨션보다 효율성 측면에서 매우 뛰어나다. | ||
| - 파이썬에서 존재하는 타입들은 모두 클래스이기 때문에 매직 메소드를 이용하여 연산이 가능하다. | ||
|
|
||
| ## 핵심 개념 | ||
|
|
||
| <!-- 가장 중요하다고 생각하는 개념이나 배운 점을 작성해주세요 --> | ||
|
|
||
| #### 딕셔너리로 제너레이터 컴프리헨션 불가능하다. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제너레이터 컴프리헨션이라는 개념이 뭔가요? |
||
|
|
||
| - 딕셔너리는 key value로 구성되어야 하기 때문 | ||
|
|
||
| #### 언패킹은 함수에서 사용할때 주의해야함. | ||
|
|
||
| - 인자를 해체하는 개념이기 때문에 해체된 인자의 개수가 함수의 인자 개수와 다르다 에러가 발생함 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수 정의에서 *args, **kwargs와 호출 시 *list, **dict의 차이는 뭘까요? |
||
|
|
||
| #### 제너레이터는 컴프리헨션보다 메모리 효울성이 좋다. | ||
|
|
||
| - 제너레이터는 지연 평가 방식이 가능하기 때문에 메모리르 더 효율적으로 사용할 수 있다. | ||
|
|
||
| #### 함수에 데코레이터 편하게 적용하려면 @를 사용하면된다. | ||
|
|
||
| - @데코레이터함수 | ||
|
|
||
| ## 실습 예제 | ||
|
|
||
| <!-- 작성한 코드 예제가 있다면 간단히 설명해주세요 --> | ||
|
|
||
| - 컴프리헨션 : 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] 참고 자료 출처가 명시되어 있다 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그렇다면 공간복잡도는 어떨까요?