Summary:
-----------
Your program will open a text file, read each line and count how many times each word appears in the file.
Each word will be stored in a dictionary such that the key is the word and the value is the number of times the word appears in the file.
Once all words have been counted, print the dictionary one element at a time as key-value pair using a for loop
Details:
--------
1) Create a [login to view URL] file in your local workspace using the data given below
2) Write a program that opens the text file and reads each line.
3) Convert each line into a list of words.
4) For each word in the list, convert the word to lower case, remove any punctation
and update a dictionary such that the word is the 'key' and the word count is the 'value'.
5) print the contents of the dictionary using a for loop such that each key-value pair is printed as below
"The number of times ", <key>, "occurs in the dictionary is --> ", <value>
6) You must include exception handling around file operations or you will lose points.
7) You must comment any function definitions (if you choose to use function ) -- describe what the function does.
If any parameters are passed, describe them. If anything is returned by the function, describe the return value.
If you implement the entire program without any functions, you should comment in appropriate places as to what the block of code is doing
Submit the proper comments.
Example:
----------
"hello hello hello foo bar"
would result in a dictionary:
{"hello": 3, "foo" : 1, "bar" : 1}
Hint:
-----
The best way to convert a character string to a list of words is with the split() method.
foo = "Computer science is fun and interesting."
# bar is a list, such that each item
# in the list is a word in the string foo
#
bar = [login to view URL]()
print(bar)
The output of the above code snippet:
['Computer', 'science', 'is', 'fun', 'and', 'interesting']
-----------------------------------------------------------------------------------
[login to view URL]
-----------------------------------------------------------------------------------
All things bright and beautiful,
All creatures great and small,
All things wise and wonderful,
The Lord God made them all
Hello, read your description and pretty sure to complete these simple tasks. Your satisfaction by the quality of work is guaranteed. We can discuss further details in pm and can start working right away. Looking forward to hear back from you.
kind regards,
$30 USD σε 1 ημέρα
5,0 (16 αξιολογήσεις)
3,9
3,9
4 freelancers δίνουν μια μέση προσφορά $31 USD για αυτή τη δουλειά
Dear sir, How are you?
My work completion time is fastest and the price is very good.
I am a PYTHON expert.
I will ensure that all the data you want is accurate and fast.
You will see through my profile that I have guaranteed great python work for many clients.
I will wait for your good response.
Thanks and Best regards!
JinXueTian