Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Created February 12, 2019 06:57
Show Gist options
  • Save jreisinger/0b9ec7e645ae866087f56b4a086fcc12 to your computer and use it in GitHub Desktop.
Save jreisinger/0b9ec7e645ae866087f56b4a086fcc12 to your computer and use it in GitHub Desktop.
#!/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