py_tip_05.py

#!/usr/bin/python3
# ==================================================================
# From YouTube video:
#    10 Python Tips and Tricks For Writing Better Code
#
# test.txt
#-------------------------------------------------------------------
# aaa bbb ccc ddd
# eee fff ggg
# hhh iii
# jjj
#
# ------------------------------------------------------------------
# Note the results of 'split' is:
# ['aaa', 'bbb', 'ddd', 'eee\nggg', 'hhh', 'iii\njjj', 'kkk\nlll\n\n']
#
#===================================================================

with open('test.txt','r') as f:
    file_content = f.read()

print(f'>>>{file_content}<<<')

words = file_content.split(' ')

print(f'<><>{words}<><>')

word_count = len(words)
print(word_count)