일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Python
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- attribute
- 315. Count of Smaller Numbers After Self
- Class
- kaggle
- 43. Multiply Strings
- data science
- iterator
- 컴퓨터의 구조
- Decorator
- 시바견
- 파이썬
- Generator
- 운영체제
- 밴픽
- DWG
- shiba
- Protocol
- t1
- 715. Range Module
- 30. Substring with Concatenation of All Words
- 프로그래머스
- Substring with Concatenation of All Words
- concurrency
- LeetCode
- Convert Sorted List to Binary Search Tree
- Python Implementation
- Python Code
- Today
- Total
목록Generator (3)
Scribbling
Basic behavior of Coroutines def coroutine(): print('started') x = yield print('received: ', x) c = coroutine() next(c) c.send(3) 1) "next(c)" or "c.send(None)" primes the coroutine -> coroutine now waits at 'yield' expression 2) c.send(3) sets x to 3, re-executing the coroutine 3) At the end, coroutine raises StopIteration Example: coroutine to compute a running average def averager(): total, c..
Sequence Protocol To make a custom data type have Sequence Protocol, you need to implement "__iter__" method. Even though "__getitem__" method is enough for now, you should implement "__iter__" method as well for later compatibility. A classic iterator Below is a classic implementation - not a rolemodel - of an iterator. import re import reprlib class Sentence: def __init__(self, text): self.tex..
1. Iterator __iter__, __next__를 가진 객체를 iterator protocol을 지원한다고 일컫는다. class Counter: def __init__(self, limit): self.num = 0 self.limit = limit def __iter__(self): return self def __next__(self): if self.num < self.limit: ret = self.num self.num += 1 return ret else: raise StopIteration for i in Counter(10): print(i, end=' ') 클래스에서 __getitem__ 메서드만 구현해도 이터레이터가 된다. class Counter: def __init__(sel..