본문 바로가기

분류 전체보기

(205)
[python3] sys.stderr.write(f"ERROR: {exc}") 에러 해결법 pip install --upgrade pip 명령어를 쳤을때 아래와 같은 에러가 뜰 때가 있다. Collecting pip Downloading https://files.pythonhosted.org/packages/ca/31/b88ef447d595963c01060998cb329251648acf4a067721b0452c45527eb8/pip-21.2.4-py3-none-any.whl (1.6MB) 100% |████████████████████████████████| 1.6MB 805kB/s Installing collected packages: pip Found existing installation: pip 8.1.1 Uninstalling pip-8.1.1: Successfully uninstal..
[프로그래머스] 위장 - python 문제 https://programmers.co.kr/learn/courses/30/lessons/42578?language=python3 코딩테스트 연습 - 위장 programmers.co.kr 해결 def solution(clothes): classificate = {} # 의상 타입별 개수 구하기 for clothe in clothes: if clothe[1] in classificate: classificate[clothe[1]] += 1 else: classificate[clothe[1]] = 1 # 조합의 수 구하기 answer = 1 for key in classificate.keys(): answer *= (classificate[key]+1) # 아무것도 안입는 경우 제외 return an..
[elasticsearch] document의 특정 필드값 수정하기 - POST API/python 엘라스틱 서치에서 특정 document의 특정 필드의 값을 변경하고 싶다면 아래와 같은 API를 통해서 수정할 수 있다. document update API POST 인덱스명/_update/다큐먼트ID { "doc": { "수정할 필드1":"수정하고자 하는 값", "수정할 필드2":"수정하고자 하는 값" } } python elasticsearch 모듈을 통한 수정 from elasticsearch import Elasticsearch es = Elasticsearch([{'host': '엘라스틱 서치 IP', 'port':9200}], http_auth=('계정', '패스워드')) es.update(index='인덱스명', id = 다큐먼트ID, body = {"doc":{"수정하고자 하는 필드1":"..
[python] datetime 날짜와 시간 차이 구하기 파이썬으로 두 날짜 간의 차이를 알고 싶다면 어떻게 해야할까? 또는 시간 차이를 알려면? 시간 차이 구하는 법 from datetime import datetime # 현재 시간을 가져온다. now = datetime.now() print(now) # 비교할 과거 시점에 대한 정보 past = datetime.strptime("20210305", "%Y%m%d") print(past) # 단순히 빼주기만 하면 두 시간의 차이를 구할 수 있다. diff = now - past print(diff) 출력 2021-06-26 20:48:48.724421 2021-03-05 00:00:00 113 days, 20:48:48.724421 단순히 datetime 형식의 두 날짜를 - 해주면 된다. 여기서 일수 차이..
[프로그래머스] 전화번호부 - python 해결 과정 일단 문제는 아래와 같다. https://programmers.co.kr/learn/courses/30/lessons/42577?language=python3 코딩테스트 연습 - 전화번호 목록 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 구조 programmers.co.kr 첫 시도 방법 1. phone_book을 숫자 길이순으로 정렬 ["12", "123", "456", "5678"] 2. 맨 처음 원소가 나머지 원소의 접두어인지 비교. 비교가 끝나면 다음 원소를 기준으로 비교. Code def solution(phone_book): # 방법 1 # 낮은 길이의 숫자부터..