I am trying to search for similar words in Python given a wildcard pattern, for example in a text file similar to a dictionary- I could search for r?v?r? and the correct output would be words such as 'rover', 'raver', 'river'. This is the code I have so far but it only works when I type in the full word and not the wildcard form.
name = input("Enter the name of the words file:\n"
pattern = input("Enter a search pattern:\n")`
textfile = open(name, 'r')
filetext = textfile.read()
textfile.close()
match = re.findall(pattern, filetext)
if match is True:
print(match)
else:
print("Sorry, matches for ", pattern, "could not to be found")
Use dots for blanks
Also, match is a string, so you want to do
if match!=""orif len(match)>0,whichever one suits your code.