✔️Python 20

[String Manipulation] Group Anagrams [Python] Tim sort

박상길님의 를 보며 문제를 풀고 정리한 것입니다. 그룹 애너그램 문제 출처: https://leetcode.com/problems/group-anagrams/submissions/ 문제 Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: strs = ["eat","tea","tan..

[String Manipulation] Most Common Word

박상길님의 를 보며 문제를 풀고 정리한 것입니다. 가장 흔한 단어 (Most Common Word) 문제 출처: https://leetcode.com/problems/most-common-word/ 문제 Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique. The words in paragraph are case-insensitive and the answer should b..

[String Manipulation] Reverse String

박상길님의 를 보며 문제를 풀고 정리한 것입니다. 1. 문자열 뒤집기 (Reverse String) 문제 출처: https://leetcode.com/problems/reverse-string/ 문제 Write a function that reverses a string. The input string is given as an array of characters s. Example 1: Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: s = ["H","a","n","n","a","h"] Output: ["h","a","n","n","a","H"] Constraints: 1 > s = ["h", "e", "l..

[String Manipulation] Intro & Valid Palindrome

박상길님의 를 보며 문제를 풀고 정리한 것입니다. 1. 문자열 조작 (String Manipulation)이란 문자열을 변경하거나 분리하는 등의 여러 과정을 말함 2. 문자열 처리와 관련한 알고리즘이 쓰이는 대표적인 분야 정보 처리 분야: 어떤 키워드로 웹 페이지를 탐색할 때 문자열 처리 애플리케이션을 이용한다. 또한 많은 정보가 문자열로 구성되어 있으므로 문자열 처리는 정보 처리에 핵심이 된다. 통신 시스템 분야: 문자열 데이터 전송은 문자열 처리 알고리즘이 나오게 된 기원이기도 하며, 데이터 전송에서 문자열 처리는 매우 중요하다. 프로그래밍 시스템 분야: 프로그램은 그 자체가 문자열로 구성되어 있고, 컴파일러나 인터프리터에서 문자열을 해석하고 기계어로 번환하는 과정에서 정교한 문자열 처리 알고리즘이 ..

[High Performance] Profiling & Numpy for Matrix and Vector Computation

올해 초에 딥러닝 분석을 돌리는데 필요한 많은 연산에서 어느 부분에 병목이 발생하는지 프로파일링 해보고, 해결하는 과정을 진행했다. 시간 복잡도가 O(|V|^3)인 floyd_warshall 알고리즘을 사용하고 있었기 때문에 여기서 시간이 오래 걸리는게 아닐까 예상하였지만 프로파일링 결과를 보니 행렬과 벡터 연산을 순수 파이썬 리스트로 구현한 곳에서 속도가 늦어지고 있다는 것을 알게 되었다. 그래서 이를 numpy를 사용한 행렬과 벡터 연산으로 수정하였고, 그 결과 시간을 약 86% ~ 97% 정도로 줄일 수 있었다. 책을 참고 하였으며, 이 과정에서 배운 '프로파일링으로 병목 지점 찾기'와 '행렬과 벡터 산술 계산에서 numpy가 순수 파이썬보다 빠른 이유'를 중점으로 정리하고자 한다. 1. 프로파일링..

[TDD] Python Testing Framework - Pytest, unittest - Coverage

1. Coverage Code Coverage에 대해서는 를 보고 쉽게 이해할 수 있었습니다. Installation: $ pip install coverage Unittest: $ coverage run --branch -m unittest Pytest: $ coverage run --branch -m pytest Use $ coverage report -m to report on the results $ coverage html to get annotated HTML listings detailing missed lines 2. Coverage report tool Codecov + Github Actions Github actions에서 main 브랜치에 push 나 PR을 하면 pytest와 un..

Dev/SW Engineering 2021.08.16

[TDD] Python Testing Framework2 - Pytest, Unittest - mocking

1. Mock mocking이 필요한 경우를 예시로 들고, 해당 mocking을 Unittest로 구현할 때와 Pytest로 구현할 때를 나누어서 살펴보겠습니다. 1) Random result mocking import random import requests def roll_dice(); print("rolling...") return random.randint(1, 6) def quess_number(num): result = roll_dice() if result == num: return "You won!" else: return "You lost!" 이런 코드가 있을 때, Random 모듈이 잘 작동하는지가 아닌 random의 결과가 있을 때, 내가 작성한 guess_number 함수가 기대대로..

Dev/SW Engineering 2021.08.16

[Python] 동시성과 병렬성 문법 - Multiprocess

1. join 과 is_alive을 이용한 process 실행 큰 틀 한 프로세스만 생성하여 실행해보기 위한 큰 틀은 아래와 같다. join 메소드는 파이썬에게 프로세스가 종료 될 때까지 대기하도록 지시하고, is_alive는 process가 실행되고 있는지 여부를 반환한다. join([timeout]) If the optional argument timeout is None (the default), the method blocks until the process whose join() method is called terminates. If timeout is a positive number, it blocks at most timeout seconds. Note that the method retu..

[Python] 동시성과 병렬성 문법 - GIL과 Multithreading

1. 멀티 스레드, 멀티 프로세스 개념 [운영체제] Thread 에서 정리한 적이 있음. a. Processs vs Thread Process: 컴퓨터에서 연속적으로 실행되고 있는 컴퓨터 프로그램, 즉 메모리에 올라와 실행되고 있는 독립적인 프로그램 인스턴스 Thread: 프로세스 내에서 동작되는 여러 실행의 흐름 단위 이렇게 하나의 프로세스 내에서 생성된 thread끼리 해당 프로세스의 영역을 공유한다. - Processs는 독립적, Thread는 프로세스의 서브넷 - Process는 각각 독립적인 자원을 가진다. Thread는 프로세스의 자원을 공유한다. Process는 별도의 Code, Data, Stack, Heap을 독립적으로 가지는 반면 Thread는 Stack만 독립적으로 가지고 Code, ..

[TDD] Python Testing Framework 1 - Pytest, unittest

1.Installation and Getting Started (unittest / pytest) 1) Unittest unittest는 python에 내장되어있어 따로 설치하지 않아도 되는 표준 라이브러리 입니다. 그래서 바로 import해서 사용할 수 있습니다. import unittest 2) Pytest pytest는 설치를 하고, import하여 사용합니다. $ pip install pytest import pytest 2. Naming Conventions (unittest / pytest) 1) Unittest 파일명: test로 시작 Unittest에서는 지정된 파일은 반드시 모듈로 import 가능해야 합니다. 메소드명: test로 시작 단위 테스트의 기본 구성 블록인 TestCase를 ..

Dev/SW Engineering 2021.05.21