Hello guys and girls i am really getting upset from this exercise.
The Desired output is —>
['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']
this is my code
fname = input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh :
line = line.rstrip()
if line not in lst :
lst.append(line)
a = lst[0]
b = lst[1]
c = lst[2]
d = lst[3]
e = a + ' ' + b + ' ' + c + ' ' + ' ' + d
e = e.split()
e.sort()
print(e)
this is my output ---->
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'and', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'is', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'sun', 'the', 'the', 'the', 'through', 'what', 'window', 'with', 'yonder']
i can’t get rid of the repeated words like ‘and’ , ‘is’ , ‘sun’ , ‘the’
i tried the e.remove()
but the exercise told me not to use this function.
i know there supposed to be a loop but i can not figure it out i tried a lot so please tell me what to do to get rid of the repeated words !
Thanks in advance