1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vichka [17]
3 years ago
12

The following function open_file() opens a file called 'example.txt' and returns the file pointer. This function is called withi

n main and the file pointer is used to read lines in the file. Create a dictionary called 'dict_of_words' that have words as 'keys' and (integer) counters as values. The counter values keep a count of the number of times a word has appeared in the text file. In the end, store the dictionary key, values in a list, sort and print the list on the screen.
Note that the counts are not case-sensitive, that is, 'Word' is the same as 'word' or 'wORd'.
Also, note that your program should account for if a ',' (comma) separates two words, e.g. 'food, water, electricity'
Example:
Contents of input text file:
I do not think there is any thrill that can go through the human heart like that felt by the inventor as he sees some creation of the brain unfolding to success such emotions make a man forget food sleep friends love everything.
Nikola Tesla

Output:
[('a', 1), ('any', 1), ('as', 1), ('brain', 1), ('by', 1), ('can', 1), ('creation', 1), ('do', 1), ('emotions', 1), ('everything', 1), ('felt', 1), ('food', 1), ('forget', 1), ('friends', 1), ('go', 1), ('he', 1), ('heart', 1), ('human', 1), ('i', 1), ('inventor', 1), ('is', 1), ('like', 1), ('love', 1), ('make', 1), ('man', 1), ('nikola', 1), ('not', 1), ('of', 1), ('sees', 1), ('sleep', 1), ('some', 1), ('success', 1), ('such', 1), ('tesla', 1), ('that', 2), ('the', 3), ('there', 1), ('think', 1), ('thrill', 1), ('through', 1), ('to', 1), ('unfolding', 1)]

Use the code below:

def open_file():
fpointer = open('example.txt')
return fpointer

def main():
dictlist = []
fp = open_file()
#loop to iterate over lines in file

for key, value in dict_of_words.items():
temp = (key,value)
dictlist.append(temp)
print(sorted(dictlist))

main()
Computers and Technology
1 answer:
dsp733 years ago
8 0

Answer:

Code is given as below:

Explanation:

def open_file():

   fpointer = open('example.txt')

   return fpointer

def main():

   dictlist = []

   dict_of_words = dict()

   fp = open_file()

   # loop to iterate over lines in file

   for line in fp:

       for word in line.split():

           if(not dict_of_words.get(word)):

               dict_of_words[word] = 1

           else:

               dict_of_words[word] += 1

   for key, value in dict_of_words.items():

       temp = (key.lower(), value)

       dictlist.append(temp)

   print(sorted(dictlist))

main()

You might be interested in
Which option describes wearable technology?
kotykmax [81]
My opinion is the answers A and D. I would choose A if you can only choose one, though.
7 0
3 years ago
Read 2 more answers
Why is soccer the most popular sport
riadik2000 [5.3K]

Soccer is the most 'popular' sport in the world because it is played more than any other by kids growing up. ... So, yeah, ya see…Soccer's not so much “The Beautiful Game'' as it is…

5 0
4 years ago
Read 2 more answers
Omar sends a PDF file to his teacher. He then prepares another copy of the presentation that includes only the slides he wants t
maria [59]

Answer:

D. Custom Slide Show

Explanation:

Correct on edg

7 0
3 years ago
Which standardized framework was developed by NIST to be used as a guidance document designed to help organizations assess and m
MariettaO [177]

The standardized framework developed by NIST to be used as a guidance document is;

NIST Special Publication (SP) 800-37 Risk Management Framework for Federal Information Systems and Organizations:

<h3>Computer Frameworks</h3>

The standardized framework by NIST from the FISMA guideline is the NIST Special Publication (SP) 800-37 Risk Management Framework for Federal Information Systems and Organizations.

Now, this standardized framework is simply a Life Cycle Approach used for Security and Privacy, and also it details the Risk Management Framework (RMF).

Read more about Computer Framework at; brainly.com/question/25236672

3 0
3 years ago
an early type of GUI is created, which includes windows, pop-ups, icons, and menus. What year did this happen? Please help!!! qu
Dahasolnce [82]

Answer:

1979

Sources:

Wired

InventHelp

hope i helped :D

3 0
3 years ago
Other questions:
  • Which payment type is best if you are trying to sick to a budget?
    15·1 answer
  • What color does Sam obtain when he mixes white with a color? Sam is painting a landscape and needs to paint the sky light blue.
    9·2 answers
  • Which of the following statements are true?
    14·1 answer
  • If Word finds a potential error in a document, a red, green, or blue wavy underline flags the problem.
    14·1 answer
  • Why is plastic durable?
    9·2 answers
  • To what would you compare the transport layer?
    13·1 answer
  • Write a Java program to encrypt and decrypt a phrase using two similar approaches, each insecure by modern standards. The first
    15·1 answer
  • List three differences between word and excel
    8·1 answer
  • Which type of boot authentciation is more secure?
    10·1 answer
  • HELPPPPP 20 POINTS CORRECT ANSWER GETS BRAINLIEST<br>sorry wrong amount of points ;-;
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!