Created
June 20, 2018 09:17
-
-
Save RichardEllicott/6fb57a943f47dc712c82a55240e066b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
filename = sys.argv[1] # first argument | |
string_to_count = sys.argv[2] # second argument | |
with open(filename) as f: # opens a file, f becomes the file object, this is the official PEP8 style for reading files | |
text = f.read() # we need to read the data from that file | |
print(text.count(string_to_count)) # strings have a special function in python that can count the occurrences of a string within them |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment