단어찾기 비교


import json
from difflib import get_close_matches

Dictionary 타입 json으로 사용

data = json.load(open("word_data.json"))

# input으로 단어입력받아서
# data안의 단어 항목 찾기
# 비슷하면 정확도가 높은 단어 선택
get_close_matches(input_word, data.keys())[0]

get_close_matches(word, possibilities, n=3, cutoff=0.6)
    word         : 기준단어
    possibilities : 기준단어에 부합되는 항목들
    n=3          :  possibilities 중 3개선정 (default=3)
    cutoff       :  선정기준 정확도 (1=동일한 단어, default=0.6)
                     만족하는 항목 없을경우 [] 리턴
    가장 정확도가 높은항목이 제일 앞에 옴

기타 셋 변환
data.upper()
data.lower()
data.title()



* 자동으로 찾아주는건 좋은데
  Database 쓰지 않으면 너무 느리고 비효율적이다....

Python dates & times

>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2019, 3, 3, 15, 7, 30, 931160)
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2019, 3, 3, 15, 8, 5, 66884)
>>> yesterday = datetime.datetime(2019,3,2,15,0,0,0)
>>> yesterday
datetime.datetime(2019, 3, 2, 15, 0)
>>> now-yesterday
datetime.timedelta(1, 485, 66884)
>>> delta = now-yesterday
>>> delta
datetime.timedelta(1, 485, 66884)
>>> datetime.timedelta(1, 485, 66884)
datetime.timedelta(1, 485, 66884)
>>> delta.days
1
>>> delta.total_seconds()
86885.066884
>>> after = now+datetime.timedelta(days=2)
>>> after
datetime.datetime(2019, 3, 5, 15, 8, 5, 66884)
>>> yesterday
datetime.datetime(2019, 3, 2, 15, 0)
>>> now
datetime.datetime(2019, 3, 3, 15, 8, 5, 66884)
>>> after = now+datetime.timedelta(seconds=10002)
>>> after
datetime.datetime(2019, 3, 3, 17, 54, 47, 66884)
>>> import time
>>> lst = []
>>> for i in range(5):
...     lst.append(datetime.datetime.now())
...     time.sleep(1)
...
>>> lst
[datetime.datetime(2019, 3, 3, 15, 24, 41, 101860), datetime.datetime(2019, 3, 3, 15, 24, 42, 102824), datetime.datetime(2019, 3, 3, 15, 24, 43, 103479), datetime.datetime(2019, 3, 3, 15, 24, 44, 104411), datetime.datetime(2019, 3, 3, 15, 24, 45, 104583)]
>>> for i in lst:
...     print(i)
...
2019-03-03 15:24:41.101860
2019-03-03 15:24:42.102824
2019-03-03 15:24:43.103479
2019-03-03 15:24:44.104411
2019-03-03 15:24:45.104583
>>>