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
A force of 50n acts on a body of mass 5kg. calculate acceleration produced .​
guapka [62]

Answer:

Force = 50n

mass = 5kg

Force = m * acc

50 = 5 * A

A = 50/5

A = 10 m/s^2

HOPE IT HELPS!!!

Explanation:

7 0
3 years ago
The mechanism for preventing traffic that is perceived to be dangerous to the network is known as a a0.
nikklg [1K]
I would go with firewall
6 0
3 years ago
During the _____ of the systems development life cycle (SDLC), an information system is operating, enhancements and modification
Neporo4naja [7]

Answer:

Maintenance Phase

Explanation:

One of the concepts employed in project management for describing stages involved when carrying out an information system development project is the systems development life cycle (SLDC). The cycle which starts from carrying out a feasibility study and ends in maintenance is a highly used conceptual model. There are 5 major stages or phase and they are the; Requirement Phase, Design Phase; Implementation Phase, Test Phase, and the Maintenance phase. The maintenance phase comes when testing has been complete and all enhancement and modifications have already been developed, and the system is operating.

5 0
3 years ago
Explain why it is important to continually evaluate long-term goals
lilavasa [31]
It is important to continually evaluate long term goals because one's life situation can change from day to day. For example, one can be without work for many months and despairing of ever getting work when finally conditions improve and work becomes available. Life is full of opportunities and sooner or later opportunities will arise so that whereas the long term situation looked economically bleak before, now it can improve significantly.
3 0
4 years ago
​A(n) ________ database makes it possible to store information across millions of machines in hundreds of data centers around th
Kisachek [45]

Answer:

distributed

Explanation:

According to my expertise in information technology, it seems that the type of database being described is a distributed database. Like mentioned in the question this is a database that works by saving information in data centers from various locations and information is processed through multiple database node. This allows information to be more secured, faster, and also acts as a fail-safe in case of any malfunction where data may otherwise be lost.

3 0
3 years ago
Other questions:
  • _ are typically comprised of a mix of _ and _
    11·2 answers
  • What does the hexadecimal number 2D represent in the binary system?
    9·1 answer
  • A _____ provides a file-system interface which allows clients to create and modify files.
    11·1 answer
  • Microsoft word 2016
    14·1 answer
  • G Suite for Education offers which benefits to educators? (Select all that apply.) Select All Correct Responses Android apps ava
    10·1 answer
  • Last semester, Henri bought his textbooks over the Internet and saved a considerable amount of money. Classes start in a few day
    12·2 answers
  • Angle parking spaces are generally entered at an angle about __________ from the curb.
    8·2 answers
  • Which is an example of compound meter?<br> 2/4<br> O 4/4<br> O 6/8<br> Onone of the above
    5·2 answers
  • Helpppppp meeeeeeeeeeeeeeeeee
    12·1 answer
  • The alveolar walls and the pulmonary capillaries form the:
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!