I am not aware of the cause of this error, but I am trying to take the words within a file, read the lines, split them, and then add those words into a list and sort them. It is simple enough but I seem to be getting an error which states ''str' object cannot be interpreted as an integer' I am not aware of the cause for this error and would appreciate some assistance.
I haven't tried a lot of methods as I was sure this one would work and I don't have a good idea of how to go around it. The file I'm using contains this:
But soft what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief
here is the code that I am using...
#userin = input("Enter file name: ")
try:
l = [] # empty list
relettter = open('romeo.txt', 'r')
rd = relettter.readlines()
# loops through each line and reads file
for line in rd:
#add line to list
f = line.split(' ', '/n')
l.append(f)
k = set(l.sort())
print(k)
except Exception as e:
print(e)
the results should print a sorted list of the words present in the poem.