ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 데이터 구조(Data Structure)
    BoostCourse 2022. 12. 29. 18:45

    기본 데이터 구조로는 다음과 같은 구조가 있다.

    1. 스택과 큐(stack & queue with list)

    2. 튜플과 집합(tuple & set)

    3. 사전(dictionary)

    4. Collection 모듈

     

    • 스택: Last In First Out (LIFO)
      push - list.append(sth)
      pop - list.pop()
      ex) Delivery System

     

    • 큐: First In First Out (FIFO)
      enqueue - list.append(sth)
      dequeue - list.pop(0)

     

    • 튜플: Unchageable
      ex) 학번, 이름, 우편번호 등
      ** t = (1,) - 값이 하나일 경우 , 필요

     

    • 집합: 중복 불허, 순서 없음
      s.add()
      s.remove() - 지우려는 element가 없으면 KeyError 발생
      s.discard() - 지우려는 element가 없어도 정상종료
      s.update([])
      s.clear()
      s1.union(s2), s1 | s2
      s1.intersection(s2), s1 & s2
      s1.difference(s2), s1 - s2

     

    • 사전: Key 값을 활용하여 Value 값을 관리
      dict.items() - Dict 데이터 출력
      ** unpacking - for k, v in dict.items():
      dict.keys() - Key 값 출력
      dict.values() - Value 값 출력
      dict[key] = value - Dict 추가 or 변경
      key in dict.keys()
      value in dict.values()

     

    • collections: Python Built-in 확장 자료 구조(모듈)
      ex) from collections import deque
      deque - rotate, reverse 등 Linked List의 특성을 지원함
      OrderedDict - '이전' Dict와 달리 데이터를 입력한 순서대로 dict를 반환함
      defaultdict - value를 지정하지 않은 key의 value를 0(혹은 지정값)으로 가짐
      Counter - Sequence type의 data element의 개수를 dict 형태로 반환
      namedtuple - Tuple 형태로 Data 구조체를 저장하는 방법

    'BoostCourse' 카테고리의 다른 글

    벡터가 뭐에요?  (0) 2023.01.05
    Numpy  (1) 2023.01.05
    Exception/File/Log Handling  (0) 2023.01.02
    Module and Project  (0) 2023.01.02
    Python Object Oriented Programming  (0) 2022.12.31

    댓글

Designed by Tistory.