일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- LeetCode
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- data science
- DWG
- 315. Count of Smaller Numbers After Self
- 715. Range Module
- Regular Expression
- 30. Substring with Concatenation of All Words
- 프로그래머스
- Substring with Concatenation of All Words
- 운영체제
- Class
- attribute
- Protocol
- concurrency
- Generator
- Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- Python
- kaggle
- Decorator
- iterator
- shiba
- 시바견
- 파이썬
- 43. Multiply Strings
- Python Code
- 밴픽
- t1
- Today
- Total
목록Python (33)
Scribbling
ID operator returns the object's memory address. We use it to compare objects' identities. morgan = {'name': 'hoesu', 'age':29} hoesu = morgan print(hoesu is morgan) print(id(hoesu), id(morgan)) "==" operator calls __eq__() method in dict class and checks whether the objects have the same value or not. morgan = {'name': 'hoesu', 'age':29} anonymous = {'name': 'hoesu', 'age':29} print(morgan == a..
Decorator is a callable that takes another function as its parameter. Decorator is executed during 'import time'. The key idea about closure you must understand is that it can access to 'nonlocal' variables outside the function. Take a look at the below exmaple. def make_averager(): series = [] def averager(new_val): series.append(new_val) return sum(series) / len(series) return averager avg = m..
Some traditional design patterns can be simplified by making good use of first-order functions in python. Let's see the below example. 1. Goal: Calculate total price and discount for each order 2. There are three discount strategies; - fidelitypromo: if the customer's fidelity >= 1000, then 5% of the total - bulkitempromo: if q >= 20 for an item, then 10% of the item - largeorderpromo: if type >..
Python memoryview function returns memory view objects. So why use it? Memory view is a safe way to expose 'buffer protocol' in python. Buffer protocol allows an object to expose its inner data without copying. As buffer protocol is only available at the C-API level, memoryview is present to expose the same protocol at Python level. Example1: how memoryview works arr = bytearray('XYZ', 'utf-8') ..
In this post, I am dealing with 'magic methods' to create more pythonic data models. First Example: Card Deck Card = namedtuple('Card', ['rank', 'suit']) class FrenchDeck: ranks = [str(n) for n in range(2, 11)] + list('JQKA') suits = ['Spades', 'Diamonds', 'Hearts', 'Clubs'] def __init__(self): self._cards = [Card(rank, suit) for suit in FrenchDeck.suits for rank in FrenchDeck.ranks] def __len__..
This post is about Knuth Shuffle, a shuffle algorithm. - This algorithm allows random shuffle, giving all permuations of array equal likelihood. - No need for additional arrays, so memory complexity is O(1). - Time complexity is O(N) Code is pretty simple as below. To give all permuations of a particular array equal likelihood, all the number should have the same probability to be placed in a ce..
Each of programming language has their own way of 'Integer Representation'. In most languages, integers are represented with 32 bits and the most significant bit (the leftmost bit) is for the sign of it. As a result, usual '32-bit int representation' has range of [-2**31+1, 2**31]. * 2**31 (INT_MAX) is 0xFFFFFFFF * -2*31+1 (-INT_MAX) is 0x80000000 (by 2's complement) However, python has somewhat..
Below is my own python implementation of AVL Tree. Feel free to use it and refer to the bottom most part of the code to see how it works. As there are already so many materials dealing with the algorithms of AVL data structure, I won't explain about them at this article. Instead, I upload a concise implementation of AVL tree. class TreeNode: def __init__(self, val): self.val = val self.left = No..
Below is the python implementation of segment tree data structure. Segment tree is often used to query range sum within O(logN) time complexity. As it is storing range information of the data, this data structure can be useful when you are looking for information on the basis of various ranges. * Below implementation is for range sums. class SegmentTreeNode: def __init__(self, start, end, val, l..
Decorator는 이미 만든 함수를 수정하지 않고, 함수 주변을 감싸는 방식으로 함수에 추가 기능을 구현한다. def trace(func): # wrapper는 아래처럼 가변 인수로 만들 수 있다. # 가변 인수가 아닌 경우, 원래 함수의 parameter 형태와 일치해야 한다. def wrapper(*args, **kwargs): ret = func(*args, **kwargs) print('{0}(args={1}, kwargs={2}) -> {3}'.format(func.__name__, args, kwargs, ret)) # 원래 함수가 return이 필요한 경우에는 wrapper도 return이 필요하다. return ret return wrapper @trace def get_max(*args..