강의지원 게시판

[프로그래밍기초] Hamlet 단어검색

확-통
작성자
formal formal
작성일
2016-06-07 18:21
조회
1185
string = raw_input("Input some words:")
string = string.split()

with open("hamlet.txt","r") as f:
content = f.readlines()
for index, item in enumerate(content, 1):
for word in string :
if word not in item:
break
else:
print index, item


===================================================

xfile = open("hamlet.txt")
lines = xfile.readlines()
data = raw_input("input: ")
WordList = data.split()
WordCount = len(WordList)
count = 0

for line in lines:
count += 1
for i in range(WordCount):
if (line.find(WordList[i]) != -1):
if(i == (WordCount-1)):
print(str(count) + " " + line)
break
continue
else:
break

xfile.close()