Question

Please solve. How do I create my own text file? Where do I save it so...

Please solve.

How do I create my own text file? Where do I save it so that it is recognized by python? Do I have to import it into my code?

the prompt:

Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order.

An example file along with the correct output is shown below:

example.txt

the quick brown fox jumps over the lazy dog

Enter the input file name: example.txt

brown
dog
fox
jumps
lazy
over
quick
the
0 0
Add a comment Improve this question Transcribed image text
Answer #1
fileName = input("Enter the input file name: ")
f = open(fileName)
lst = []
for line in f:
    words = line.strip().split(" ")
    lst += words
lst.sort()
for x in lst:
    print(x)

Add a comment
Know the answer?
Add Answer to:
Please solve. How do I create my own text file? Where do I save it so...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3:Write a program that inputs a text file. The program should print the unique words...

    Python 3:Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order.   Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order An example file along with the correct output is shown below: example.txt the quick brown fox jumps over the lazy dog Enter the input file name: example.txt brown dog fox jumps lazy over quick the

  • -Brief description of the program: - input(s) and output(s) - brief description or relationship b...

    -Write in C++ language. -Brief description of the program: - input(s) and output(s) - brief description or relationship between inputs and outputs Submission Instructions: Submit only.c files in the designated Dropbox on D2L Problem 1 (25 points): Write a C program that a) reads one line (sentence) at a time from a text file called inputtext.txt (on D2L), b) reverses the words on that line, c) prints (on the screen) the modified line and d) write the modified line in...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • Write a program that inputs a text file. The program should print the unique words in...

    Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Note: The sort function sorts first numbers, then capital letters, then lowercase letters. That is fine for this assignment as you can see from the sample output. But even if the same word appears multiple times in the file it should only be displayed once in the output. (python)

  • IN C++ Write a program in c++ that will read from a file the following sentence:...

    IN C++ Write a program in c++ that will read from a file the following sentence: The quick brown fox jumps over the lazy dog Each word must be read into one location in an array beginning with the first element. You must declare an array as follows: char *words [9] ; // this is an array of c- strings. HINT words[0] will contain "the" words[1] will contain "quick" write a function int length (const char *a) to determine the...

  • You will be writing some methods that will give you some practice working with Lists. Create...

    You will be writing some methods that will give you some practice working with Lists. Create a new project and create a class named List Practice in the project. Then paste in the following code: A program that prompts the user for the file names of two different lists, reads Strings from two files into Lists, and prints the contents of those lists to the console. * @author YOUR NAME HERE • @version DATE HERE import java.util.ArrayList; import java.util.List; import...

  • i am trying to write a subroutine in assembly that removes all occurrences of a given...

    i am trying to write a subroutine in assembly that removes all occurrences of a given character in a string. The subroutine takes two parameters: the string pointer, and the character to be removed. Write a C code that calls this subroutine. The string is defined in the C source code file as global. Assume the assembly and C code are in separate files. Use Keil/uVision to test your program where the C code should ask the assembly subroutine to...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Hi, need this question ansered in c++, has multiple levels will post again if you can...

    Hi, need this question ansered in c++, has multiple levels will post again if you can complete every level so keep an eye out for that. here is a sketch of the program from the screenshot int main (int argc, char** argv) { enum { total, unique } mode = total; for (int c; (c = getopt(argc, argv, "tu")) != -1;) { switch(c) { case 't': mode = total; break; case 'u': mode = unique; break; } } argc -=...

  • I am working on Exercise 5.8 from Fundamentals of Python 2nd edition. Do you have a...

    I am working on Exercise 5.8 from Fundamentals of Python 2nd edition. Do you have a solution for this item? Thank you. Here is the code I have. I just need 1 instance of each to show in my output. should look like: AM 3 I 3 SAM 3 Thank you... # Put your code here #fileName = input("Enter the file name: ") fileName = "example.txt" #fileName = "kgtest.txt" inputFile = open(fileName, 'r') text = inputFile.read() #print(text) words = text.split()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT