Created
February 12, 2019 06:57
-
-
Save jreisinger/0b9ec7e645ae866087f56b4a086fcc12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" Reads a file and returns the number of lines, words | |
and characters similar to the UNIX wc utility. | |
""" | |
infile = open("word_count.txt") | |
lines = infile.read().splitlines() | |
line_count = 0 | |
word_count = 0 | |
char_count = 0 | |
for line in lines: | |
words = line.split() | |
line_count += 1 | |
word_count += len(words) | |
char_count += len(line) | |
print("{} lines, {} words, {} characters".format(line_count, word_count, | |
char_count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment