일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- ChatGPT
- dacon
- 백준
- 편스토랑 우승상품
- 프로그래머스
- 편스토랑
- Git
- 자연어처리
- Kaggle
- 맥북
- hackerrank
- AI 경진대회
- gs25
- 데이콘
- leetcode
- github
- Baekjoon
- 더현대서울 맛집
- Real or Not? NLP with Disaster Tweets
- ubuntu
- 파이썬
- 캐치카페
- 코로나19
- PYTHON
- Docker
- 금융문자분석경진대회
- programmers
- SW Expert Academy
- 우분투
- 프로그래머스 파이썬
- Today
- Total
목록
반응형
2020/12 (31)
솜씨좋은장씨
Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. Example 1: Input: head = [1,0,1] Output: 5 Explanation: (101) in base 2 = (5) in base 10 Example 2: Input: head = [0] Output: 0 Example 3: Input: head = [1]..
Given an array nums of integers, return how many of them contain an even number of digits. Example 1: Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd number of digits). 7896 contains 4 digits (even number of digits). Therefore only ..
wand 라이브러리 설치 $ pip install wand 위의 라이브러리는 ImageMagick이라는 것을 활용하므로 이것도 같이 설치해주어야 합니다. ImageMagick 설치 Ubuntu 에서 설치하는 방법 sudo apt-get install libmagickwand-dev 위의 명령어로 설치한 이후에 사용할 설정을 수정해주면 완료입니다. [Python] wand.exceptions.PolicyError: not authorized `./test.pdf' @ error/constitute.c/ReadImage/412 해결방법 wand와 ImageMagick을 설치한 후 pdf를 tiff로 변환하려고 할 때 wand.exceptions.PolicyError: not authorized `./test..
wand와 ImageMagick을 설치한 후 pdf를 tiff로 변환하려고 할 때 wand.exceptions.PolicyError: not authorized `./test.pdf'@ error/constitute.c/ReadImage/412 위와 같은 오류를 만나게 되었습니다. 위는 imageMagick의 설정에 pdf 관련 설정이 none으로 설정되어있기 때문입니다. 이를 해결하는 방법은 다음과 같습니다. 먼저 설정을 변경할 파일을 vi 편집기로 열어줍니다. $ sudo vi /etc/ImageMagick-6/policy.xml $ sudo vi /etc/ImageMagick/policy.xml 위의 두 경로 중 본인의 설치 버전에 맞는 버전의 경로로 들어가면됩니다. 여러 부분 중에서 위의 부분을 ..
이 글에서는 자주 사용하는 정규식을 정리하려합니다. XXXX년 XX월 XX일 ( 년 월 일 형식 추출 정규식 ) import re value = "오늘은 2020년 12월 29일 입니다." pattern = r"\d+년 \d+월 \d+일" regex_result = re.search(pattern, value) result = regex_result.group() 특수문자 제거 정규식 import re regex_text = re.sub('[-=+,#/\?:^$.@*\"※~&%ㆍ!』\\‘|\(\)\[\]\`\'…》]', '', text) XX-XXX-XXXX | XX-XXXX-XXXX | XXX-XXX-XXXX | XXX-XXXX-XXXX ( 전화번호 추출 정규식 ) import re value = "내..
Given an array of unique integers salary where salary[i] is the salary of the employee i. Return the average salary of employees excluding the minimum and maximum salary. Example 1: Input: salary = [4000,3000,1000,2000] Output: 2500.00000 Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively. Average salary excluding minimum and maximum salary is (2000+3000)/2= 2500 Examp..
Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive). Example 1: Input: low = 3, high = 7 Output: 3 Explanation: The odd numbers between 3 and 7 are [3,5,7]. Example 2: Input: low = 8, high = 10 Output: 1 Explanation: The odd numbers between 8 and 10 are [9]. Constraints: 0
Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Find the kth positive integer that is missing from this array. Example 1: Input: arr = [2,3,4,7,11], k = 5 Output: 9 Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9. Example 2: Input: arr = [1,2,3,4], k = 2 Output: 6 Explanation: The miss..
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4->3->2->5->NULL 첫번째 시도 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseBetween(self, head: ListNode, m: int, n: int) -> ListNode:..
최근 Github이 master branch에서 main branch로 이름이 바뀌면서 git도 업데이트가 필요했습니다. 먼저 본인의 git 버전이 어떤 버전인지 확인해봅니다. $ git version git version 2.7.4 main branch를 기본 branch로 설정할 수있는 git의 버전은 2.28.0 이상이라고 합니다. 업데이트를 하기위해서 $ sudo apt-get upgrade 위의 명령어로 설치를 시도하였으나 실패하여 찾아보니 아래의 방법으로 업데이트가 가능했습니다. $ sudo add-apt-repository ppa:git-core/ppa -y $ sudo apt-get update $ sudo apt-get install git -y 설치 후 다시 git 버전을 확인해보면 $..
1일 1문제 280일차! 오늘의 문제는 프로그래머스의 최고의 집합 문제입니다. 코딩테스트 연습 - 최고의 집합 자연수 n 개로 이루어진 중복 집합(multi set, 편의상 이후에는 집합으로 통칭) 중에 다음 두 조건을 만족하는 집합을 최고의 집합이라고 합니다. 각 원소의 합이 S가 되는 수의 집합 위 조건을 만족 programmers.co.kr Solution def solution(n, s): answer = [] if s // n < 1: answer = [-1] else: s_n = s // n for i in range(n): answer.append(s_n) s_p_n = s % n idx = len(answer) - 1 for i in range(s_p_n): answer[idx-i] = a..
Elasticsearch에서 종종 reindexing 을 할 경우가 있습니다. 최근 프로젝트를 진행하면서 기존에 ES 서버에 인덱싱되어있는 인덱스를 새롭게 만든 서버에서 인덱싱을 할 일이 있었습니다. kibana에서 reindex 명령어를 입력하여 시도를 하였는데 Not whitelisted in reindex.remote.whitelist 위와 같은 오류를 만나게 되었습니다. 이를 해결하는 방법은 다음과 같습니다. 먼저 elasticsearch가 설치된 곳으로 이동합니다. 거기서 elasticsearch.yml 파일을 찾아 한 줄을 추가해주면 됩니다. reindex.remote.whitelist: "0.0.0.0:9200" reindex.remote.whitelist: "원하는IP:PORT" 그리고 나..
각 페이지별 이미지 변환 ( pdf to jpg ) - pdf2image 활용 여러 페이지로 구성되어있는 pdf 파일을 각 페이지별 이미지로 변환하는 방법에 대해서 적어보려 합니다. 먼저 이 과정을 진행하기 위해서 필요한 라이브러리를 설치합니다. pdf2image A wrapper around the pdftoppm and pdftocairo command line tools to convert PDF to a PIL Image list. pypi.org pip install pdf2image 그 다음 아래의 코드를 활용하여 pdf파일의 각 페이지를 jpg 이미지로 변환하면 됩니다. #-*- coding:utf-8 -*- from pdf2image import convert_from_path file_n..
docker에서 mecab을 활용하려고 이것 저것 여러 페이지를 참고하며 시도해보았던 내용 중 성공했던 내용에 대해서 적어보려 합니다. Dockerfile FROM ubuntu:16.04 # Python RUN apt-get update && \ apt-get install -y --no-install-recommends apt-utils && \ apt-get -y install software-properties-common && \ add-apt-repository -y ppa:deadsnakes/ppa && \ apt-get update --fix-missing && \ apt-get -y install --fix-missing python3.6 && \ apt-get -y install --fi..
1일 1문제 279일차의 문제는! 프로그래머스의 이상한 문자 만들기 입니다. 코딩테스트 연습 - 이상한 문자 만들기 문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 programmers.co.kr 첫 번째 시도 def solution(s): s_list = list(s) for i in range(len(s_list)): if i % 2 == 0: s_list[i] = s_list[i].upper() elif i % 2 == 1: s_list[i] = s_list[i].lower() answer = "".join(s_list) return answer 이 문제는 짝수..
docker를 사용하면서 코드를 수정하면 이미지를 다시 만들어야 하는데 코드 내에 API를 호출할때 활용하는 url, endpoint 정보나 여러 설정값들을 바꿀때마다 다시 이미지를 만들고 실행하는데 번거로움이 있었습니다. 이런 설정값들을 좀 더 편하게 수정할 수 있는 방법을 최근에 알게되어 적어보려 합니다. 먼저 python 코드 내에서 설정값을 적는 부분을 수정하여 줍니다. config.py 수정 전 NER_INFO = { "ip":"0.0.0.0", "port" : "23232" } config.py 수정 후 import os NER_INFO = { "ip":os.environ.get("NER_IP", "0.0.0.0"), "port":os.environ.get("NER_PORT", "23232")..
1일 1문제 278일차의 문제는 프로그래머스의 두 개 뽑아서 더하기 입니다. 코딩테스트 연습 - 두 개 뽑아서 더하기 정수 배열 numbers가 주어집니다. numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요. 제한 programmers.co.kr Solution from itertools import combinations def solution(numbers): return list(sorted(set([sum(combs) for combs in combinations(numbers, 2)]))) Solution 해설 먼저 이 문제는 숫자가 담긴 리스트를 주면 여기서 숫자를 두개..
최근에 API를 만들면서 API 요청에 대한 로그를 남겨야하는 일이 있어 python의 logging을 활용하여 로그를 남기려고 코드를 작성하여 실행하였는데 로그를 찍으면 찍을 수록 중복되어 찍히는 로그가 점점 많아 졌습니다. 수정 전 코드 import os import logging import logging.handlers def request_log(query, subj, prop, top1_prop, elapsed_time): dir_path = "./log_data/kbqa" if not (os.path.isdir(dir_path)): os.makedirs(os.path.join(dir_path)) logger = logging.getLogger("kbqa_search") logger.setLe..
Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1). Example 1: Input: nums = [3,4,5,2] Output: 12 Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12. Example 2: Input: nums = [1,5,4,5] Output: 1..
이 글에서는 Mac OS 가 설치된 맥북, 아이맥, 맥 등에서 파이썬을 활용하여 코딩을 할 때 영어나 숫자로 되어있는 이름의 파일은 문제가 없는데 윈도우에서 가져온 파일 중에 한글로 된 파일을 가져와서 데이터를 로드하여 사용하려하면 오류가 나지는 않는데 제대로 파일에 접근하여 다른 작업을 하지 못할때 해결하는 방법에 대해서 적어보려합니다. 원인 먼저 이렇게 한글로 된 파일은 맥과 윈도우에서 한글을 표현할 때 사용하는 방식이 다르기 때문입니다. 맥에서 만든 파일을 윈도우로 가져갔을 때 파일이름의 자모가 분리되어 보이는 문제도 같은 이유로 발생합니다. 맥은 NFD ( Normalization Form Decomposition ) 방법을 윈도우는 NFC ( Normalization Form Compositio..
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. A string is represented by an array if the array elements concatenated in order forms the string. Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "bc"] Output: true Explanation: word1 represents string "ab" + "c" -> "abc" word2 represents string "a" + "bc" -> "abc" The stri..
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth. Example 1: Input: accounts = [[1,2,3],[3,2,1]..
You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original order. Given the string command, return the Goal Parser's interpretation of command. Examp..
Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays. A subarray is a contiguous subsequence of the array. Return the sum of all odd-length subarrays of arr. Example 1: Input: arr = [1,4,2,5,3] Output: 58 Explanation: The odd-length subarrays of arr and their sums are: [1] = 1 [4] = 4 [2] = 2 [5] = 5 [3] = 3 [1,4,2] = 7 [4,2,5] = 11 [2,5,3] = 10 [1,4,2,..
최근 제가 만든 코드의 실행 속도를 측정해야하는 일이 있었습니다. 다양한 방법이 있지만 저는 datetime을 활용하여 측정해보았습니다. datetime을 활용하는 방법은 다음과 같습니다. import datetime 먼저 datetime 라이브러리를 import 합니다. start_time = datetime.datetime.now() # ( 측정을 하고자 하는 코드 ) end_time = datetime.datetime.now() datetime.datetime.now( ) 를 활용하여 코드 실행 전, 후 시간을 가져옵니다. elapsed_time = end_time - start_time 그 다음 코드 실행 후 시간에서 코드 실행 전 시간을 빼줍니다. 여기서 얻은 elapsed_time을 활용하여 ..
You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city. It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city. Example 1: Input: paths = [["London","New York"],["New..
Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target. Letters also wrap around. For example, if the target is target = 'z' and letters = ['a', 'b'], the answer is 'a'. Examples: Input: letters = ["c", "f", "j"] target = "a" Output: "c" Input: letters = ["c", "f", "..
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well. Example 1: Input: 1->2->3->3->4->4->5 Output: 1->2->5 Example 2: Input: 1->1->1->2->3 Output: 2->3 Solution from collections import Counter # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=Non..
이 글에서는 pdf2image 라이브러리를 활용하여 pdf 파일을 image로 변환하는 방법에 대해서 적어보려 합니다. 먼저 pdf 파일목록을 os 를 활용하여 받아옵니다. import os file_list = os.listdir("./source/") 저는 source 디렉토리에 3개의 pdf 파일을 담아두었기에 os의 listdir을 활용하여 ./source/ 디렉토리의 파일 목록을 가져왔습니다. file_list ['TA_클러스터링_핵심어추출.pdf', 'Word_Embedding_자질을_이용한_한국어_개체명_인식_및_분류.pdf', 'journal_ktsde_9-4_752015269.pdf'] from pdf2image..
Python에서 pdf2image 라이브러리를 활용하여 pdf를 이미지로 변경하려는 코드를 실행하려고하니 아래와 같은 오류가 발생하였습니다. from pdf2image import convert_from_path pages = convert_from_path("./source/" + file_list[0], 500) --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) ~/anaconda3/lib/python3.7/site-packages/pdf2image/pdf2image.py in pdfinfo_from_path(pdf_path..