Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io
- def wc(path):
- with open(path, "r", encoding="utf-8") as f:
- lines = words = chars = 0
- for line in f:
- lines += 1
- words += len(line.split())
- chars += len(line)
- return lines, words, chars
- def wc_str(string):
- f = io.StringIO(string)
- lines = words = chars = 0
- for line in f:
- lines += 1
- words += len(line.split())
- chars += len(line)
- return lines, words, chars
- def wc_split(string):
- f = string.split('\n')
- lines = words = chars = 0
- for line in f:
- lines += 1
- words += len(line.split())
- chars += len(line)
- return lines, words, chars
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement