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
Rama09 [41]
3 years ago
14

Write a program that opens a specified text file then displays a list of all the unique words found in the file.

Computers and Technology
1 answer:
klemol [59]3 years ago
3 0

Answer:

filename = input("Enter file name with extension:")

words = []

with open(filename, "r") as file:

   # read the file line by line, with each line an item in the returned list

   line_list = file.readlines()

   # loop through the list to get the words from the strings

   for line in line_list:

       word_list = line.split(" ")

       for i in word_list:

           words.append(i)

# use the set() to get the unique items of the list as a set

# and convert it back to a list, then display the list.

su_words = set(words)

unique_words = list(su_words)

print(unique_words)

Explanation:

The python program gets the file name from the user input method. The with keyword is used to open and read the file which is read line by line as a list of strings (each line is a string). The for loop is used to append each word to the words list and the set() function cast the words list to a set of unique words. The set is in turn converted back to a list and displayed.

You might be interested in
Consider the following algorithms. Each algorithm operates on a list containing n elements, where n is a very large integer.
DochEvi [55]

We have that the appropriate statement will be

  • An algorithm that accesses only the first 10 elements in the list, regardless of the size of the list. Which of the algorithms run in reasonable time

III only.

Option B

From the question we are told

Consider the following <u>algorithms</u>. Each <u>algorithm</u> operates on a list containing n <em>elements</em>, where n is a very large <u>integer</u>.

I. An algorithm that accesses each <u>element</u> in the list twice.

II. An <em>algorithm </em>that accesses each <u>element </u>in the list n times.

III. An <u>algorithm</u> that accesses only the first 10 elements in the list, regardless of the size of the list. Which of the <em>algorithms </em>run in <em>reasonable </em>time?

<h3>Algorithm  </h3>

Generally In order to get <em>admission </em>to every thing in the list twice, the algorithm has to traverse the listing twice,

which leads to 2*n entry to operations.

And if the every factor is accessed n times, the listing will be traversed n time, which leads to n^2 get right of entry to operations.

If n is a very giant <em>integer</em>, each 2*n and n^2 are plenty larger.

So, there will be <em>solely </em>ten entry to operations and this algorithm will have a sensible jogging time.

Therefore

An algorithm that accesses only the first 10 elements in the list, regardless of the size of the list. Which of the algorithms run in reasonable time

III only.

Option B

For more information on  algorithm  visit

brainly.com/question/950632

4 0
2 years ago
An “AI” (artificial intelligence) could be used in:
zhannawk [14.2K]
I would say D. But l may be incorrect. Al bots are not made for games, but are made for information.

Sorry l can't be much of help, but l do hope that I did help you out in a way.
8 0
3 years ago
Which of the following are examples of IT
Advocard [28]

Answer:

Computer hardware engineer

Systems analyst

Database administrator

7 0
3 years ago
Give the name and the syntax of the HTML Tag which is <br><br>used for creating a Hypertext Link.​
Annette [7]

Answer:

<a href="enter_site_url_here">Click here to visit site!</a>

Explanation:

href is the link that the element is going to point towards. Meaning it's going to direct the end-user to that site. "Click here to visit site!" is the text that the element is going to say, and that text will have an underline. So it's best to keep it short as you don't want <u>something like this happening on your site</u>.

I'd stick with the classic "here" as the text and have the text before-hand say "Click" and after-hand say " to visit site X" with X being the site name. Or, something along those lines.

8 0
3 years ago
Each vertex in a graph of n bertices can be the origin of at most ____edges
EastWind [94]

Answer:

B. n-1

Explanation:

If there are n vertices then that vertex can be origin of at most  n-1 edges.Suppose that you have a graph with 8 vertices you can select a vertex from these 8 vertices now you have 7 other vertices.So the vertex you selected can have at most 7 edges or it can be origin of at most 7 edges.So we conclude that the answer is n-1.

6 0
3 years ago
Other questions:
  • Which type of ICS facility is used to temporarily position and account for personnel, supplies, and equipment awaiting assignmen
    15·1 answer
  • How do you represent images in binary
    6·2 answers
  • What is one method that can be used to open the Microsoft Word application?
    8·1 answer
  • In addition to the decimal number system, the number systems used most often in PLC operationand programming are ________.
    9·1 answer
  • Look at the four schematic symbols shown in the figure above. Each of the symbols is labeled with a number. Which of the followi
    11·1 answer
  • (1)similarities between backspace key and delete key. (2) different between backspace key and delete key. (3) explain the term e
    10·1 answer
  • What name is given to the method used to copy a file onto a CD
    11·1 answer
  • Explain the history of computing device of mechanical era
    7·1 answer
  • I have this questions i need to make it in a report format pages of atleast 3 pages and maximum of 5 pages​
    7·1 answer
  • A search expression entered in one search engine will yield the same results when entered in a different search engine.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!