Skip to content

Conversation

@fprtmjinho
Copy link
Collaborator

@fprtmjinho fprtmjinho commented Oct 8, 2025

학습 내용 요약

  • 제너레이터는 지연 평가 방식이 가능하기 때문에 객체에 엄청나게 많은 데이터를 넣어 생성해야 할 때에는 컴프리헨션보다 효율성 측면에서 매우 뛰어나다.
  • 파이썬에서 존재하는 타입들은 모두 클래스이기 때문에 매직 메소드를 이용하여 연산이 가능하다.

핵심 개념

딕셔너리로 제너레이터 컴프리헨션 불가능하다.

  • 딕셔너리는 key value로 구성되어야 하기 때문

언패킹은 함수에서 사용할때 주의해야함.

  • 인자를 해체하는 개념이기 때문에 해체된 인자의 개수가 함수의 인자 개수와 다르다 에러가 발생함

제너레이터는 컴프리헨션보다 메모리 효울성이 좋다.

  • 제너레이터는 지연 평가 방식이 가능하기 때문에 메모리르 더 효율적으로 사용할 수 있다.

함수에 데코레이터 편하게 적용하려면 @를 사용하면된다.

  • @데코레이터함수

실습 예제

  • 컴프리헨션 : comprehension.py
  • 언패킹 : unpacking.py
  • 제너레이터 : generator.py
  • 매직메소드 : magic_method.py
  • 데코레이터 : decorator.py

참고 자료

컴프리헨션

언패킹

제너레이터

매직메소드

데코레이터

체크리스트

  • 주제에 대한 핵심 내용을 다루고 있다
  • 실습 가능한 코드 예제가 포함되어 있다
  • 마크다운 문법이 올바르게 적용되었다
  • 참고 자료 출처가 명시되어 있다

@fprtmjinho fprtmjinho requested a review from rover0811 October 8, 2025 09:53
@fprtmjinho fprtmjinho self-assigned this Oct 8, 2025
Copy link
Member

@rover0811 rover0811 left a comment

Choose a reason for hiding this comment

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

# 문제 3: magic_method.py 확장
class Fruit(object):
    def __init__(self, name, price):
        self._name = name
        self._price = price

    def __add__(self, target):
        return self._price + target._price

apple = Fruit("사과", 100)
banana = Fruit("바나나", 100)

fruits = {apple, banana}  # 이게 작동할까요?
print(len(fruits))  # 1일까요? 2일까요?


<!-- 가장 중요하다고 생각하는 개념이나 배운 점을 작성해주세요 -->

#### 딕셔너리로 제너레이터 컴프리헨션 불가능하다.
Copy link
Member

Choose a reason for hiding this comment

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

제너레이터 컴프리헨션이라는 개념이 뭔가요?


<!-- 이번 주차에서 학습한 내용을 3-5줄로 요약해주세요 -->

- 제너레이터는 지연 평가 방식이 가능하기 때문에 객체에 엄청나게 많은 데이터를 넣어 생성해야 할 때에는 컴프리헨션보다 효율성 측면에서 매우 뛰어나다.
Copy link
Member

Choose a reason for hiding this comment

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

그렇다면 공간복잡도는 어떨까요?


#### 언패킹은 함수에서 사용할때 주의해야함.

- 인자를 해체하는 개념이기 때문에 해체된 인자의 개수가 함수의 인자 개수와 다르다 에러가 발생함
Copy link
Member

Choose a reason for hiding this comment

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

함수 정의에서 *args, **kwargs와 호출 시 *list, **dict의 차이는 뭘까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants