๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Python/Basic

[Python] ๋‘ ๋ฌธ์ž์—ด ์ผ์น˜์œจ ๊ณ„์‚ฐ

๋ฐ˜์‘ํ˜•

 

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%'

 

https://hoze.tistory.com/1741

 

๋‘ ๋ฌธ์ž์—ด์„ ๋น„๊ตํ•˜์—ฌ ์ผ์น˜์œจ ๊ตฌํ•˜๊ธฐ

ํ”„๋ž‘์Šค์–ด ๋ฒˆ์—ญ๋ณธ์˜ ์ƒ๋‹น ๋ถ€๋ถ„์ด ๊ตฌ๊ธ€์˜ ๋ฒˆ์—ญ๊ณผ ๊ณ ์Šค๋ž€ํžˆ ์ผ์น˜ํ•œ๋‹ค. ๋ฒˆ์—ญ์‚ฌ๊ฐ€ ์ œ๋Œ€๋กœ ์ผํ•œ ๊ฒƒ์ผ๊นŒ ์˜๊ตฌ์‹ฌ์ด ๋“ค ๋งŒํ•˜๋‹ค. ๋‹ค๋ฅธ ๋ฒˆ์—ญ์‚ฌ์—๊ฒŒ ๊ต์—ด์„ ๋งก๊ฒผ๋Š”๋ฐ ๋ณ„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋Š” ๋‹ต๋ณ€์ด ๋Œ์•„์™”๋‹ค๊ณ 

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

 

๋ฐ˜์‘ํ˜•