Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import listdir, path, getcwd
- def count_words(texto):
- return len(texto.split())
- def count_chars(texto):
- return len(list(texto))
- def main():
- files = [f for f in listdir(getcwd()) if f.endswith('.txt')]
- for file in files:
- print(" START ".center(80, 'x'))
- total_chars, total_words = 0, 0
- with open(file) as f:
- lines = f.readlines()
- for line in lines:
- total_chars += count_chars(line)
- total_words += count_words(line)
- print("(%s) Total characteres: %d\n(%s) Total words: %s\n" % (file, total_chars, file, total_words))
- print(' END '.center(80, 'x'))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment