You may consider using a database if your data gets too big.
a viable option is SQLite which is a simple file-based database.
First create a table for your words
try:
connection = sqlite3.connect("database.db")
cursor = connection.cursor()
cursor.execute('''
CREATE TABLE "words" (
"id" INTEGER,
"word" TEXT NOT NULL UNIQUE,
PRIMARY KEY("id" AUTOINCREMENT)
);
''')
except sqlite3.Error as error:
print("Failed to execute the above query", error)
finally:
if connection:
connection.close()
Now you can start adding words to the table
my_word = "cat"
try:
connection = sqlite3.connect("database.db")
cursor = connection.cursor()
cursor.execute("INSERT INTO words(word) VALUES(?)", [my_word])
except sqlite3.Error as error:
print("Failed to execute the above query", error)
finally:
if connection:
connection.close()
Now to fetch the word from list do
search_word = "cat"
try:
connection = sqlite3.connect("database.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM words WHERE word=?", [search_word])
print(cursor.fetchall())
except sqlite3.Error as error:
print("Failed to execute the above query", error)
finally:
if connection:
connection.close()