IT/Python
[Python] urllib
Dragonz
2020. 11. 14. 16:35
반응형
개발사항
- http://data.pr4e.org/romeo.txt 파일울 오픈한다.
- 파일을 읽어 단어와 해당 단어가 몇 번이나 있는지 카운트하여 화면에 출력한다.
import urllib.request, urllib.parse, urllib.error
fhead = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
counts = dict()
for line in fhead :
words = line.decode().split()
for word in words :
counts[word] = counts.get(word, 0) + 1
print(counts)
END
반응형