๋ฐ์ํ
from difflib import SequenceMatcher
a_str = 'abcd'
b_str = 'bcd'
SequenceMatcher(None, a_str, b_str).ratio()
0.8571428571428571
match_rate = f'{SequenceMatcher(None, a_str, b_str).ratio()*100:.1f}%'
match_rate
'85.7%'
๋ ๋ฌธ์์ด์ ๋น๊ตํ์ฌ ์ผ์น์จ ๊ตฌํ๊ธฐ
ํ๋์ค์ด ๋ฒ์ญ๋ณธ์ ์๋น ๋ถ๋ถ์ด ๊ตฌ๊ธ์ ๋ฒ์ญ๊ณผ ๊ณ ์ค๋ํ ์ผ์นํ๋ค. ๋ฒ์ญ์ฌ๊ฐ ์ ๋๋ก ์ผํ ๊ฒ์ผ๊น ์๊ตฌ์ฌ์ด ๋ค ๋งํ๋ค. ๋ค๋ฅธ ๋ฒ์ญ์ฌ์๊ฒ ๊ต์ด์ ๋งก๊ฒผ๋๋ฐ ๋ณ ๋ฌธ์ ๊ฐ ์๋ค๋ ๋ต๋ณ์ด ๋์์๋ค๊ณ
hoze.tistory.com
https://codetorial.net/tips_and_examples/difflib.html
5. ํ์ด์ฌ ๋ ๋ฌธ์์ด ๋น๊ตํ๊ธฐ (difflib) - Codetorial
์์ from difflib import SequenceMatcher str1 = 'abcd' str2 = 'efgh' ratio = SequenceMatcher(None, str1, str2).ratio() print(ratio) ‘abcd’์ ‘efgh’์ ์ ์ฌ์ฑ์ ํ์ธํด๋ณด๋ฉด, 0.0์ ์ถ๋ ฅํฉ๋๋ค.
codetorial.net
๋ฐ์ํ
'Python > Basic' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] List - List ๋นผ๊ธฐ (0) | 2020.11.16 |
---|---|
[Python] psycopg2 ์ค์น ์ค๋ฅ (1) | 2020.11.11 |
[Python] ์์ธ ๋ฐ์ ์ํค๊ธฐ, ๋ฉ์ธ์ง ์ถ๋ ฅ (0) | 2020.10.22 |
[Python] cx_Oracle ํ๊ธ ๊นจ์ง (0) | 2020.10.20 |
[Oauth] Google, email ์ ๋ณด ์ป๊ธฐ (0) | 2020.10.09 |