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
Submit your business presentation that clearly compares and contrasts three different cell phone service plans. I have TO HAVE I
zysi [14]

Answer:

Ufone - It offers complete hybrid package for its user which includes 1000MB mobile data, 300 local call minutes, 1000 minutes on the same network and 15000 SMS.

Telenor - Telenor does not offer hybrid packages instead user has to purchase call and SMS packages separately but its packages are cheap.

Jazz - It offers unlimited data, unlimited call and SMS for the entire month. It is most suitable for professionals and businessmen who cannot keep track for their calls and SMS.

Explanation:

The cell phone service providers offer different plan for their customers. They introduces offer which is most demanded by their customers and they target their audience and tries to retain them by offering them special packages which suites them.

3 0
3 years ago
Which one is correct
maw [93]
Letter A is correct because I guest
7 0
3 years ago
Which is true of effective passwords?
mylen [45]

Answer:

It is either A. or D.

4 0
4 years ago
Which of the following careers is part of the Printing Technology pathway?
torisob [31]
Textile designer i think

6 0
3 years ago
Luke is working on a layout for a catalog. He adds cross lines on the four corners of the layout to mark out a small extra margi
Savatey [412]

Cross lines that are added on the four corners of a layout to mark out a small extra margin is called: D. trim.

<h3>What is layout design?</h3>

Layout design can be defined as a graphical design process that involves the use of one or more grids for the design of a catalog and system, so as to make the designs visually appealing to end users.

In a layout design, trim refers to the cross lines that are added on the four (4) corners of a layout to mark out a small extra margin.

Read more on layout design here: brainly.com/question/13732745

8 0
2 years ago
Other questions:
  • Use pseudocode to specify a recursive algorithm to compute the nth value of the harmonic series, for some integer n.
    5·1 answer
  • In a stream channel what is deposited first?
    7·1 answer
  • As long as you have great skills and references, you don't have to worry about how well you package that information.
    5·1 answer
  • Explain the significance of the loss of direct, hands-on access to business data that end users experienced with the advent of c
    14·1 answer
  • Handouts are pages of your presentation that you print and distribute to your audience
    10·1 answer
  • Jobs with only 7 letters
    7·2 answers
  • WHAT TYPES OF ACTIVITIES ARE PERFORMED BY HEALTH CARE SOFTWARES
    8·1 answer
  • Computing devices translate digital to analog information in order to process the information
    12·1 answer
  • 4. Sameer appointed as journalist in big news channel. News channel has its own podcast. Explain to Sameer how podcast is useful
    11·1 answer
  • 4.(L.5.1.A) Select the sentence that includes an interjection,
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!