Text Statistics
Step 1
Write some lorem ipsum text into a file. You can do this manually.
Read the file1 using Python and make a statistic of how often every word appears in the file2 and print your results to the command line.
Step 2
Now parameterize the function.3
Make the main function peek into sys.argv
4 and use all arguments to the script as input file names5, combining the results6.
-
When opening files you can easily just iterate over the lines in the file by iterating over the filehandler object itself. ↩
-
You can/should use a
dict
containing every word as a key and as the value a counter then scan the text incrementing the respective counters[^counter] ↩ -
Let the function take parameters as an input. ↩
-
You have to use
import sys
to have access tosys.argv
. ↩ -
The first argument of
sys.argv
is always the script itself. ↩ -
You can easily return multiple things by using
return value1, value2, value3
and so on, which returns a tuple(value1, value2, value3)
↩