본문 바로가기
  • 紹睿: 자유롭고 더불어 사는 가치있는 삶

Data/python·알고리즘39

[Linked list] Linked list 코드 linked list linked list는 이런 노드가 연결 되어있다. class Node: def __init__(self, item): self.val = item self.next = None class LinkedList: def __init__(self, item): self.head = Node(item) def add(self, item): cur = self.head while cur.next != None: cur = cur.next cur.next = Node(item) def remove(self, item): if self.head.val == item: self.head = self.head.next else: cur = self.head while cur.next != None.. 2018. 9. 24.
[큐와 스택] queue와 stack Queue class Queue: def __init__(self): self.items = [] def enqueue(self, item): self.items.insert(0, item) def dequeue(self): self.items.pop() def print(self): print(self.items) def size(self): return len(self.items) def clear(self): return self.items == []​ FIFO 구조로, 롤에서도 등장한다(?) 큐잡혔다!!!!!! "먼저 줄을 선 사람이 먼저 나가도록 하는 것" 만약에 먼저 큐를 돌렸는데, 다른사람이 잡힌다고 해봐라 얼마나 열받는가 ㅂㄷㅂㄷ.. queue는 enqueue와 dequeue를 이용하여 구.. 2018. 9. 24.
[python] jupyter notebook 코드를 tistory에 올리는 법. tistory에 jupyter note HTML을 올리고 싶다면, 외부컨텐츠를 클릭하여, html 소스코드를 넣으면된다. 글 안에 html 파일 내용이 다 들어가게 하기 위해서는 아래와 같이 jupyter notebook에 실행시키면 된다. from IPython.core.display import display, HTML display(HTML("")) 따로, font-family, size등 style 쪽에 가면 수정도 가능하다.. 2018. 9. 16.
[python] 알아두면 좋은 Standard Library Standard Library https://docs.python.org/3/library 1. 내장 함수 및 내장 상수 2. 내장 타입(Built-in Types) - 데이터 타입 - Exception 3. Text Processing Services - string - ** re - Regular expression - 기타(difflib, unicodedata ...) 4. Numeric 및 mathematical modules - math, cmath, random ... 5. Data Persistence/파일관련 - ** pickel(Python object serialization) - marshal - ** sqlite3 - 파일 포맷 관련: zlib, gzip 등 파일 압축 관련, csv.. 2018. 6. 29.
[python 기초] Exception 처리 Exception exceptional condition: error상황을 맏으면 raise exception 프로그램이 exception을 적절하게 처리하지 못하면 error message(=traceback)와 함께 프로그램을 종료시킨다. - raise(): 의도적으로 exception을 발생시킴 raise Exception # raise Exception # Exception - exception Hierarchy: https://docs.python.org/3/library/exceptions.html#exception-hierarchy - Custom Exception: 개발자가 직접! 예외상황이 되었을때, "이떻게 처리해라!!"라고 지정해 줄수 있다.(후속처리) Exception을 이용하면 방.. 2018. 6. 29.
[python 기초] OOP - class와 Object Object Oriented Programming python에서 class는 data type으로 본다. 1. Class와 Object class - a user-defined prototype for an object - 틀(class) -> 제품 (instance/object) class 특징 1) Encapsulation 불필요한 detail을 감추는 것 2) Polymorphism( =! Compile이 아니라, runtime에 자동적으로 obejct의 type에 따라 자동으로 작업내용이 달라지는 것 3) Inheritance: Class - subclass, Parent-child 2. Class와 Type 1) Class 만들기 - constructor - initializer 2) Attr.. 2018. 6. 29.