Hello,
I need your help with my PYTHON 3 ASSIGNMENT:
SO HERE IS THE ASSIGNMENT ITSELF:
Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alphabetical order.
You can download the sample data at http://www.py4e.com/code3/romeo.txt
HERE IS THE DESIRED OUTPUT:
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
HERE IS MY CODE WHICH I WILL NEED YOU TO USE AND MODIFY AS NEEDED:
fname=input("Enter the file name")
frapucchino = open(fname)
# Opening romeo.txt
capucchino = []
# Declaring Empty List
for line in frapucchino:
words = line.split()
for word in words:
print(word)
capucchino.sort(word)
if word not in capucchino:
capucchino.append(word.rstrip())
print (capucchino.sort())
I AM HAVING A PROBLEM WITH SORTING THE OUTPUT IN THE ALPHABETIC ORDER (FIRST GOES THE CAPITAL LETTERS AND THEN LOWER CASE LETTERS AND ALL IN THE ALPHABETIC ORDER. I AM NOT SURE HOW TO CORRECTLY USE SORT() METHOD. SO PLEASE HELP ME WITH THAT AND MATCH THE DESIRED OUTPUT.
ALSO PLEASE TAKE A PICTURE(SNAPCHAT) OF YOUR CODE IN YOUR COMPUTER OR COME UP WITH SOMETHING ELSE, BUT JUST MAKE SURE THAT I CAN SEE YOUR INDENT. PLEASE FOLLOW THE RULES OF INDENT AND SHOW ME YOUR INDENT, BECAUSE I WILL NEED INDENT(THE SPACE NEEDED PRIOR EACH LINE OF CODE) FOR BEING ABLE TO RUN THE CODE IN THE PROGRAM.
Please consider helping me. I am looking forward to hearing back from you!
Thank you a lot!
Hello, I need your help with my PYTHON 3 ASSIGNMENT: SO HERE IS THE ASSIGNMENT ITSELF:...