You are on page 1of 3

7/13/2021 I Need Python Code For This. Write A Program That ... | Chegg.

com

  Textbook Solutions Expert Q&A Study Pack Practice 

Find solutions for your homework Search

home / study / engineering / computer science / computer science questions and answers / i need python code for this. write a program that inpu…

Question: I need python code for this.


 
Write a program that inputs a te… Post a question
Answers from our experts for your tough
homework questions

I need python code for this. Enter question


Write a program that inputs a text file. The program should
print the unique words in the file in
alphabetical order. Uppercase
words should take precedence over lowercase words. For example, 'Z'
comes before 'a'.
The input file can contain one or more sentences, or be a
multiline list of words. Continue to post
An example input file is shown below: 19 questions remaining
example.txt
the quick brown fox jumps over the lazy dog
An example of the program's output is shown below:
Snap a photo from your
Enter the input file name: example.txt
phone to post a question
We'll send you a one-time download
brown
link
dog

fox
jumps
888-888-8888 Text me
lazy

over

quick
By providing your phone number, you agree to receive a one-tim
automated text message with a link to get the app. Standard
the messaging rates may apply.

Create and populate your own text file for development.

My Textbook Solutions
Expert Answer

Kalpesh Mohanta answered this


Was this answer helpful? 16 0
822 answers

Code:
Fundament... Fundament... Principles of..
inputFile = input("Enter the input file name: ")

inFile = open(inputFile)
2nd Edition 1st Edition 9th Edition
uniqueWords = []

View all solutions


for line in inFile:

words = line.split()

for currentWord in words:

currentWord = currentWord.strip(',.?!')

if currentWord not in uniqueWords:

uniqueWords.append(currentWord)

inFile.close()

uniqueWords.sort()

print()

for currentWord in uniqueWords:

print(currentWord)

Output:

https://www.chegg.com/homework-help/questions-and-answers/need-python-code--write-program-inputs-text-file-program-print-unique-words-file-alph… 1/3
7/13/2021 I Need Python Code For This. Write A Program That ... | Chegg.com

  Textbook Solutions Expert Q&A Study Pack Practice 

Comment


Up next for you in Computer Science

Write a program that Can someone help me


allows
with

the user to navigate the this in python, they are

lines
essentially the same
of text in a file. The ti See more questions
program
for subjects you study
should prompt the user
for a

See answer See answer

Questions viewed by other students

Q: Python 3:
Write a program that inputs a text file. The program should print
the unique words in the file in alphabetical
order.
Please let the output be the exact format as above

A: See answer 100% (42 ratings)

Q: A file concordance tracks the unique words in a file and their


frequencies. Write a program that displays a
concordance for a
file. The program should output the unique words and their
frequencies in alphabetical order.
Variations are to track
sequences of two words and their frequencies, or n words and their
frequencies. Please
include flowchart

A: See answer 100% (9 ratings)

Show more 

COMPANY

LEGAL & POLICIES

CHEGG PRODUCTS AND SERVICES

CHEGG NETWORK

CUSTOMER SERVICE

https://www.chegg.com/homework-help/questions-and-answers/need-python-code--write-program-inputs-text-file-program-print-unique-words-file-alph… 2/3
7/13/2021 I Need Python Code For This. Write A Program That ... | Chegg.com
© 2003-2021 Chegg Inc. All rights reserved.

  Textbook Solutions Expert Q&A Study Pack Practice 

https://www.chegg.com/homework-help/questions-and-answers/need-python-code--write-program-inputs-text-file-program-print-unique-words-file-alph… 3/3

You might also like