Python
(문자열 처리) 원래 작업하던 코드는 실행이 안되고 간이형으로 만든 코드는 잘 돌아가네요 도대체 문제가 뭔지 알려 주실 수 있는 분 조언 부탁 드립니다
def dict_match(filename, target_str ) :
  dict_file = open(filename, "r", encoding= 'utf-8')
  target_dict = dict_file.read()
  target_dict = target_dict.split('\n')
  index = 0
  while index < 3: 
    target = target_dict[index]
    if target_str.rfind(target) != -1:
      return target
    else:
      index += 1



#main process

str_file = open("string.txt", "r", encoding= 'utf-8' )
target_str = str_file.readline()
print(dict_match("dict.txt", 'target_str'))


 

아래가 간이 코드입니다.
 

a = '우리가 수식관계를 활용한다는 것은 '
b = ['할것이다', '한다는 것은', '하고싶다']

index = 0
while index < 3:
	c = b[index]
	if a.rfind(c) != -1:
		print(c)
		break
	else:
		index += 1

 아래거는 원하는 대로 '한다는 것은'이 출력되고,

위는 아무것도 뱉질 않는데...

그리고 위 쪽 코드의 str.txt는 아래의 a의 내용이 들어가 있고, dict.txt는 아래쪽의 b의 내용이 들어가 있어요

댓글 2