전체 글
-
Python Count Sort 카운트 정렬 알고리즘컴퓨터/파이썬 2020. 6. 28. 21:47
Count Sort 말 그대로 통 안에 모든 값들을 넣어 카운트(+1) 한 다음에, bucket[최소 값 ~ 최대 값], 카운트된 만큼 계속 arr[index] 에 지정하는 방식 # Time Complexity : O(n) | Space Complexity : O(n) | stable def countSort(arr): """ Args: arr (list): Array to sort Returns: arr (list): Sorted input array """ minValue = min(arr) maxValue = max(arr) - minValue # 음수 케이스 처리 buckets = [0 for x in range(maxValue + 1)] for i in arr: buckets[i - minVal..
-
Python BST 바이너리 서치 트리 Traversal + Height컴퓨터/파이썬 2020. 6. 27. 12:50
class BST: def __init__(self, value): self.value = value self.left = None self.right = None def traverse(tree, arr=[]): if tree is not None: #inOrder arr.append(tree.value) traverse(tree.left, arr) #preOrder arr.append(tree.value) traverse(tree.right, arr) #postOrder arr.append(tree.value) return arr EX) 아래 그래프는 # 그래프 생성 root = BST(10) root.left = BST(5) root.left.left = BST(2) root.left.left.le..
-
Python %, modulo operator 나머지 연산자 음수컴퓨터/파이썬 2020. 6. 24. 15:49
C 에서 -1 % 10을 하면, $-1$이 나온다. #include int main() { int a = -1 % 10; printf("%d", a); } Python 에서는 $9$라는 결과가 나온다. print(-1 % 10) C 가 옳은지 Python 이 옳은지 문제가 아니라, 작동 방식이 다르다고 한다. (파이썬에서 사용되는 modulo 연산자가 수 이론에서 더 많이 사용된다고 한다.) C는 아래와 같이 작동하고, 1. A / B = A/B -> floor(A/B) = C (ex -> -1 / 10 = -0.1 => floor(-0.1) = -1) 2. A % B = (C * B - (C*B - A)) % B (ex -> -1 % 10 = (-1 * 10 + 9) % 10 = -1) 파이썬에서는 쉽..
-
Sublime Text 3 nose2 테스트 사용하기컴퓨터/파이썬 2020. 6. 21. 21:21
결과물 pip install nose2 https://docs.nose2.io/en/latest/ Welcome to nose2 — nose2 0.6.0 documentation nose2 is the successor to nose. It’s unittest with plugins. nose2 is a new project and does not support all of the features of nose. See differences for a thorough rundown. nose2’s purpose is to extend unittest to make testing nicer and easier to under docs.nose2.io https://github.com/aprudent/Nos..
-
#3 파이썬 dictionary 딕셔너리 이용컴퓨터/파이썬 2020. 6. 20. 14:18
기본 문법 키, 값, print, update(), test_dic = {'a': {'b': 'c'}, 'd': 'e'} print(test_dic['a']['b']) # 출력 : 'c' test_dic['a'].update({'o': {'f': 'e'}}) print(test_dic) # {'a': {'b': 'c', 'o': {'f': 'e'}}, 'd': 'e'} keys(), values(), in, items() test_dic = {'a': {'b': 'c'}, 'd': 'e'} print(test_dic.keys()) # dict_keys(['a', 'd']) 최상위 key들만 표시됨 print(test_dic.values()) # dict_values([{'b': 'c', 'o': {'f'..
-
Sublime Text 3 파이썬 개발 환경 만들기컴퓨터/파이썬 2020. 6. 14. 10:44
https://www.sublimetext.com/3 결과물 사용 중인 패키지 목록 보기 ↓ 더보기 사용 중인 패키지 목록 A File Icon - 탐색기 아이콘 All Autocomplete - 모든 열려있는 파일에서 매치된 글자 찾기 BracketHighlighter (아래 사진) Color Highlighter - CSS 파일 같은 곳에서 #FFF 입력하면 색깔 미리 보기 ConvertToUTF8 - 섭라임에서 지원 안 되는 인코딩 지원 (GBK, BIG5, EUC-KR, EUC-JP) Diffy - 파일 비교 Emmet - 웹 개발을 편히 할 수 있는 도구 (참고 : https://emmet.io/) Formatter - 여러 가지 언어 Beautify, Minify KiteSublime - Ki..
-
#2 파이썬 여러가지 팁컴퓨터/파이썬 2020. 5. 30. 17:05
algoexpert 공부 일지 #2 https://www.algoexpert.io/questions 1. 변수 T/F 이용 isPeak = arr[i-1] arr[i+1] 2. range -> array a = range(0, 4) a[1] = 1 # 파이썬2에선 list object # 파이썬3에선 range object를 return해서 # lazy evaluation 3. 부등호 if 3 < a < 4: a = 3.5 4. enumerate a = "ABCD" for i,j in enumerate(a): print(i,j) # (0,A), (1,B), (2,C), (3,D) 5. 두 변수 바꾸기 a = 3, b = 4 a, b = b, a 6. 두 array 여집합(?) A-B a = [1, 2, ..
-
티스토리 Fira Code 폰트 적용하기컴퓨터/HTML & JS & TS 2020. 5. 11. 23:02
https://github.com/tonsky/FiraCode tonsky/FiraCode Free monospaced font with programming ligatures. Contribute to tonsky/FiraCode development by creating an account on GitHub. github.com 사이에 Fira Code를 적용시킨다. style 부분에 code.hljs는 테마마다 다를 수 있으니 클래스를 잘 찾아서 입력한다. (F12를 눌러 개발자 도구 열기) func main() { ch := make(chan int) ch