fname = input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
line = line.rstrip()
line=line.split()
for kdh in line:
if kdh in lst:
continue
else:
lst.append(kdh)
lst.sort()
print(lst)
결과
fname = input("Enter file name: ")
if len(fname) < 1:
fname = "mbox-short.txt"
fh = open(fname)
count = 0
for line in fh:
if not line.startswith("From:"):
continue
line= line.split()
line=line[1]
line = line.rstrip()
count+=1
print(line)
print("There were", count, "lines in the file with From as the first word")
결과
'모두를 위한 Python 특화과정 > 20171047 김동훈' 카테고리의 다른 글
python 데이터 구조-5 (0) | 2022.08.03 |
---|---|
python 데이터 구조-4 (0) | 2022.08.03 |
python 데이터 구조-2 (0) | 2022.07.27 |
python 데이터 구조-1 (0) | 2022.07.19 |
Programming for Everybody (Getting Started with Python)-7 (0) | 2022.07.19 |