2 letters
3 letters
4 letters
5 letters
6 letters
7 letters
8 letters
9 letters
10 letters
11 letters
12 letters
13 letters
14 letters
15 letters
16 letters
a letters
b letters
c letters
d letters
e letters
f letters
g letters
h letters
i letters
j letters
k letters
l letters
m letters
n letters
o letters
p letters
q letters
r letters
s letters
t letters
u letters
v letters
w letters
x letters
y letters
z letters
a letters
b letters
c letters
d letters
e letters
f letters
g letters
h letters
i letters
j letters
k letters
l letters
m letters
n letters
o letters
p letters
q letters
r letters
s letters
t letters
u letters
v letters
w letters
x letters
y letters
z letters
A-Z
Z-A
Points ASC
Points DESC
The OP code has the following issues.
(1) It checking letters rather than words with the following code lines:
for line in file2:
line = line.strip("n")
words = line.split()
for w in words:
w = w.strip()
if(w == word):
(2) Loops through the file1 & file2 for each word (very inefficient).
Code Refactored due to the above issues
from collections import Counter
from ordered_set import OrderedSet
import string
# Utility Functions
def string_to_words(s):
" Convert string to lower case words without puntuation "
# Remove punctuation, lower case and split on space
# Using remove punctuation code from https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string
return s.translate(str.maketrans('', '', string.punctuation)).lower().split()
def update_count(s, valid_words, cnt = None):
" count words in string "
if s:
if cnt == None:
cnt = Counter()
# Use generator (rather than list comprehension) to update counter i.e. https://wiki.python.org/moin/Generators
cnt.update(word for word in string_to_words(s) if word in include_words)
return cnt
if __name__ == "__main__":
# Main Code Body
with open(r'words.txt','r') as file3:
# Get set of cords that we want to include
# Use set since this is much quicker than a list to see if the is in words
# Use OrderedSet (rather than set) since this preserves the order of items
# added which allows outputting in the same order as words in file words.txt
include_words = OrderedSet()
for line in file3:
include_words.update(string_to_words(line.rstrip()))
with open(r'file1.txt','r') as file1:
cnt1 = None
for line in file1:
cnt1 = update_count(line.rstrip(), include_words, cnt1)
with open(r'file2.txt','r') as file2:
cnt2 = None
for line in file2:
cnt2 = update_count(line.rstrip(), include_words, cnt2)
with open(r'wordsInFiles.txt','w') as file4:
for word in include_words:
file4.write(f'{word} {cnt1[word]}n')
file4.write(f'{word} {cnt2[word]}n')
Example Usage
file1.txt
There are five known copies of the speech in Lincoln’s handwriting,
each with a slightly different text, and named for the people who
first received them: Nicolay, Hay, Everett, Bancroft and Bliss. Two
copies apparently were written before delivering the speech, one of
which probably was the reading copy.
file2.txt
When shall we three meet again
In thunder, lightning, or in rain?When the hurlyburly's done, When the battle's lost and won. That will be ere the set of sun.
words.txt (allows multiple words per line, ignores blank lines and punctuation)
There are five known copies When the hurlyburly's done When the battle's lost and won
wordsinfile.txt
there 1
there 0
are 1
are 0
five 1
five 0
known 1
known 0
copies 2
copies 0
when 0
when 3
the 4
the 3
hurlyburlys 0
hurlyburlys 1
done 0
done 1
battles 0
battles 1
lost 0
lost 1
and 2
and 1
won 0
won 1
What Is Meant by Word Count?
The term word count means the number of words contained within a document or passage of text. Checking your word count can ensure your text reaches or stays within a certain limit.
There are lots of reasons why a word count may be required for a passage of text, including readability and reliability reasons. Different word counts may be set depending on the audience of the text, its purpose, or both.
For example, a word count for a college essay may be set at 10,000 words to ensure the text contains significant research and is considered a reliable, in-depth paper. Whereas a journalist may have a 1,000-word count target to ensure the text is a short, easy-to-read summary for their target audience.
Professionals, students, authors, journalists, or anyone that needs to write a passage of text will usually find it important to know the word count.
How to Check Word Count
There are numerous ways you can check your word count. You can use Microsoft Word, Google Docs, or an online Word Counter Tool.
How to check word count using Microsoft Word
To check your word count using Microsoft Word, you can:
- Select the text you want to check
- You’ll find the word count in the bottom left-hand corner of the screen
How to check word count using Google Docs
To check your word count using Google Docs, you can:
- Select Tools
- Select Word Count
- View your word count
What Is the Word Counter Tool?
The Word Counter Tool is an online website that tells you the word count of a passage of text. The tool instantly counts the number of words and shows you the results. It can be used to make sure your text is of a certain length.
The Word Counter Tool can be used on a computer, laptop, or mobile device.
How Does the Word Counter Work?
The Word Counter Tool works by calculating the total number of words contained within a passage of text in real time.
It will count the words as you write, or it will show you the total number of words within text that you have copied and pasted into the box.
Using the tool, you can check the following information:
- Word count
- Unique word count
- Character count (with and without spaces)
- Sentence count
- Paragraph count
- Reading time
The Word Counter Tool is especially helpful if you are working on a mobile device and need to quickly check your word count.
How to Use the Word Counter
It’s easy to check your word count using the Word Counter.
To use the tool, simply:
- Start typing or copy and paste your text into the box
- Check your word count
Download Article
Download Article
Are you looking for an easy way to check the word count in your Microsoft Word document? Word has an easy-to-use, built-in tool that keeps track of your word count in each of its versions, including desktop, mobile or online. This wikiHow article will teach you how to view the word count for a section of text or your entire document in Microsoft Word.
-
1
Launch Microsoft Word. This can be done by double clicking on the Word icon on your desktop, in your Taskbar (Windows) or Dock (Mac). If you don’t see an icon, click on the ‘Start» menu in the lower left of your PC’s screen. Click on the ‘All Programs» drop down and select Microsoft Word.[1]
- On Mac, click on the Launchpad (a gray rocketship) icon in your dock. Type ‘Word’ in the search bar at the top of the screen.
-
2
Navigate to an existing document. To open a document, go to the File menu, and then click on Open. A dialog box will appear with a list of available documents.[2]
Advertisement
-
3
Select a document. In the dialog box, navigate to the document you wish to open. Select the document, and once it’s highlighted, click on Open in the lower right of the dialog box.
-
4
Select Tools. Once your document is open, select the Tools menu at the top center of the window.[3]
- This step only applies to a MAC OS.
-
5
Scroll to Word Count. In the Tools menu dropdown, click on «Word Count.»
- If you’re not using a Mac, you won’t see any Tools heading at the top. In this case, go to the Review tab at the top of your document. Once there, you’ll see «Word Count» on the left-hand side of the section.
-
6
Review your word count. A box will open displaying the number of words, as well as the number of characters, paragraphs, lines and pages, contained in your document.
- In many documents, the word count is displayed live on the left side of the bottom bar of the document window. Click on this word count to get additional information, such as the number of pages and characters.
Advertisement
-
1
Place your cursor at the beginning of the text you wish to count. Click on the beginning of the sentence, paragraph or section of text for which you want a word count.
-
2
Highlight the section of text. Drag your cursor to the end of the text section, which should now be highlighted in blue.
-
3
Click on the Tools menu. Select the Tools menu at the top center of the document window.
-
4
Click on Word Count. Select Word Count from the Tools menu dropdown. A box displaying the number of words, characters, lines, pages and paragraphs will appear on the screen.
- The word count for a selected portion of text will usually be displayed in the bottom bar of your document.
Advertisement
-
1
Launch the Microsoft Word mobile app. On your smartphone or tablet, tap on the Word app to launch it.
-
2
Open a document. The app will usually open the last document you were working on. If not, you will see a list of recently-opened files. Tap on the file you wish to work on.
-
3
Tap the Edit menu. Once your document is open, tap on the Edit menu (a capital «A» with a pencil icon) on top center of your screen. The Edit menu will open in the bottom half of your screen.
- In Word for iPad, simply tap on the «Review» menu at the top center of the tablet’s screen.
-
4
Tap on «Home.» Home is located on the left side of the Edit menu bar. This will open a pop-up menu.
-
5
Tap on «Review.» The Review menu is near the bottom of the Edit menu pop-up.
-
6
Tap on «Word Count.» Word Count is near the bottom of the Review menu. When you tap it, the number of words, characters and pages in your document will be displayed.
- In Word for iPad, word count is an icon, several lines with the numbers «123» displayed in the upper left, in the main menu bar under the Review menu.
- Highlight a section of text by tapping on it with your fingers, then tap on Word Count to display the number of words in the highlighted portion of your document.
Advertisement
-
1
Launch Word online. Navigate to office.live.com and log in with your Microsoft ID and password or choose to use the free version.
-
2
Open a document. On the left side of your screen, select a recent document.
- If you don’t see the document you want to edit, select Open from One Drive or Open from Dropbox in the lower left corner of the window.
-
3
Review the word count. Once you have an open document, check the bottom left, side of the document. The word count automatically appears in the lower scroll bar.
Advertisement
Add New Question
-
Question
How do I select the area to word count in Word 2016?
Highlight the passage; it should show the word count.
-
Question
When I am in the header area, Word will not show me a word count. What can I do?
Select all of the words in the header and the word count for the words you highlighted will be displayed in the word count box on the status bar.
-
Question
I don’t see Word Count in the lower left corner. Why not?
Right click on the status bar and click on «Word Count» so that it has a tick next to it.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
-
On Word for PC/Mac, make sure the Microsoft Word window is fully maximized. Otherwise, the window can be moved within your viewable area, and the Word Count in the lower portion of the document could be hidden.
-
To ensure the word count is always visible in your documents, select View from the Preferences menu in the upper left corner of your Mac or PC. The check the box to the left of «Live Word Count.»
Thanks for submitting a tip for review!
Advertisement
About This Article
Article SummaryX
1. Open the document.
2. Find the word count at the bottom-left corner.
3. Click the word count for more info.
4. Highlight a section to see the word count for that section.
Did this summary help you?
Thanks to all authors for creating a page that has been read 919,360 times.