How to sum up the word count for each person in a dialogue?
问题 I'm starting to learn Python and I'm trying to write a program that would import a text file, count the total number of words, count the number of words in a specific paragraph (said by each participant, described by 'P1', 'P2' etc.), exclude these words (i.e. 'P1' etc.) from my word count, and print paragraphs separately. Thanks to @James Hurford I got this code: words = None with open('data.txt') as f: words = f.read().split() total_words = len(words) print 'Total words:', total_words in