• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

get_number_of_target_words에서요…

18.08.11 21:19 작성 조회수 103

0

결과 값이 달라서요 질문 드립니다

def get_number_of_target_words(filename, target_words):

contents = get_file_contents(filename)

contents_list = contents.upper().split()

result = 0

for word in contents_list:

if target_words.upper() in word:

result += 1

이거랑

print(contents.lower().count(target_words.lower()))

'Hi'를 target word로 할 때 값이 각각 3928과 3938로 다른데, 그 이유가 뭔가요...?

답변 1

답변을 작성해보세요.

0

split을 했기 때문으로 보입니다. Hi가 붙어있는 경우와 떨어져있는 경우를 카운트했는가 차이입니다.