Search
Duplicate

매칭 점수

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

import re def get_url(p): return re.search(r'<meta property="og:url" content="https://(\S+)"', p).group(1) def get_external_links(p): return re.findall(r'<a href="https://(\S+)">', p) def count_words(p, word): cnt = 0 for w in re.findall(r'[a-z]+', p): if w == word: cnt += 1 return cnt def solution(word, pages): word = word.lower() scores, urls = {}, [] for page in pages: page = page.lower() url = get_url(page) urls.append(url) defaultscore = count_words(page, word) scores[url] = scores.get(url, 0.0) + defaultscore extlinks = get_external_links(page) for extlink in extlinks: scores[extlink] = scores.get(extlink, 0.0) + defaultscore / len(extlinks) maxscore = max(scores.values()) print(maxscore) for i, url in enumerate(urls): if scores[url] == maxscore: return i
Python
복사

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges