일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- LeetCode
- Decorator
- data science
- 시바견
- 밴픽
- kaggle
- attribute
- concurrency
- 43. Multiply Strings
- Protocol
- Python
- 프로그래머스
- shiba
- 315. Count of Smaller Numbers After Self
- iterator
- DWG
- Convert Sorted List to Binary Search Tree
- Class
- 파이썬
- Python Implementation
- 715. Range Module
- 운영체제
- Substring with Concatenation of All Words
- Generator
- Regular Expression
- Python Code
- 컴퓨터의 구조
- 109. Convert Sorted List to Binary Search Tree
- t1
- 30. Substring with Concatenation of All Words
- Today
- Total
목록전체 글 (382)
Scribbling
파이썬에서는 데이터 속성과 메서드를 통틀어 속성이라고 한다. 메서드는 단지 호출가능한 속성이다. 프로퍼티를 사용하면 클래스인터페이스를 변경하지 않고도 공개 데이터 속성을 접근자 메서드(getter & setter)로 대체할 수 있다. 파이썬 인터프리터는 obj.attr과 같은 점 표기법으로 표현되는 속성에 대한 접근을 __getattr__()과 __setattr__() 등 특별 메서드를 호출하여 평가한다. 사용자 정의 클래스는 __getattr__() 메서드를 오버라이드하여 '가상 속성'을 구현할 수 있다. 1. 동적 속성을 이용한 데이터 랭글링 다음과 같은 json data를 랭글링 하는 예제를 살펴보자. { "Schedule": { "conferences": [{"serial": 115 }], "ev..
크게 두 단계로 풀 수 있다. 1) 알파벳 조합이 동일한 집합끼리 나눈다. 2) 각 집합 내에서 단어를 연결하고, 소 집합의 갯수를 구한다. This prob can be solved within two steps. 1) Group words by alphabet combinations 2) Connect words in each group and then get the number of small groups Code is quite straightforward, so I guess there's no need to explain more. Time complexity would be (O(N**2*k)), where N is the number of words and k is length of a w..
Thread vs Asyncio 스레드나 코루틴을 통해 콘솔 에니메이션을 구현할 수 있다. 먼저 스레드를 이용하는 코드이다. Console animation can be implemented with either threads or coroutines. First, with thread. import threading import itertools import time import sys class Signal: go = True def spin(msg, signal): write, flush = sys.stdout.write, sys.stdout.flush for char in itertools.cycle('|/-\\'): status = char + ' ' + msg write(status) flus..
img0 = img1 = img2 = 'img' cap0 = cap1 = cap2 = 'cap' dataset = [(img0, cap0), (img1, cap1), (img2, cap2)] list = [(1, 2), (3, 4), (5, 6)] print(*list) for x in zip(*list): print(x) print(*dataset) imgs, caps = zip(*dataset) print(imgs) l1 = 'abc' l2 = '123' l3 = '가나다' for pair in zip(l1, l2, l3): print(pair)
Web downloads in three different styles - sequential download - concurrent.futures - asyncio With heavy input/output workload, we can make the best out of concurrency. Below is the code that downloads flag gif files sequentially. import os import time import sys import requests POP20_CC = ('CN IN US ID BR PK NK BD RU JP' 'MX PH VN ET EG DE IR TR CD FR').split() BASE_URL = 'http://flupy.org/data/..
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..
For a given recipe, we need to check whether all the necessary elements can be supplied. If an element belongs to supplies, it's a piece of cake. Now the question is to deal with elements that belong to recipes. We can think of recipes as a graph with cycles. Plus, if there's a cycle among certain recipes, they can never be cooked. class Solution: def findAllRecipes(self, recipes: List[str], ing..
Else block For-Else Else block is executed when the 'for loop' was not stopped by any break. for i in range(1, 1): else: print('Else block is executed') for i in range(1, 10): if i == 8: break else: print('Else block is executed') While-Else Works the same for 'for-else'. while False: break else: print('Else block executed') Try-Else try: dangerous_call() after_call() except OSError: log('OSErro..
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..
In this post, we add operator overloading code to custom 'Vector' class in the previous post. https://focalpoint.tistory.com/300 Python: Sequence Protocol To learn sequence protocol in Python, we create a custom vector class. from array import array import math import reprlib class Vector: typecode = 'd' def __init__(self, components): self._component.. focalpoint.tistory.com Vector Class is as ..