I'm trying to run the following code but I keep getting this error every time I run it:
[Errno 2] No such file or directory: 'words_sorted.txt'
This is the code I'm trying to run but can't figure out how to not get this error. I have also attached the txt. file
#function definition
def words_with_letters(words, letters):
#if letters is empty string then return words list
if letters == "":
return words
#new list for storing all the subsequences
subseq = []
#iteration over the words list
for word in words:
index = 0
#iteration over the word string
for char in word:
#letter which is initialized to the first letter of letters string
letter = letters[index]
#if letter is found in the word string
if char == letter:
#updating the letter to next letter of the letters string
index += 1
#if end of letters is reached, adding the word to subsequences
if index == len(letters):
subseq.append(word)
break
return subseq
#creating empty list for storing the words in text file
words = []
#opening the text file in the read mode
with open("words_sorted.txt") as file:
#iterating over the file object
for line in file:
#removing the newline character from the line and adding word to the words list
word = line.strip()
words.append(word)