Question: So I have a wordlist containing 3 words:

```
Apple
Christmas Tree
Shopping Bag

```

And I know only certain characters in the word and the length of the word, for instance:

> 
> *???i???as ?r??*
> 
> 
> 

where the **?** means it's an unknown character and I want to type it into the console and get an output of ALL the words in the word list containing these characters in these places and with this amount of characters. 

Is there any way I can achieve this? I want my program to function in the same way *<https://onelook.com/>* works.

Answer: 
You can turn your expression into a regex and try matching with that:

```
import re

words = [
    'Apple',
    'Christmas Tree',
    'Shopping Bag'
]

match = '???i???as ?r??'
regex = '^' + match.replace('?', '.') + '$'  # turn your expression into a proper regex

for word in words:    # go through each word
    if re.match(regex, word):   # does the word match the regex?
        print(word)

```

Output:

```
Christmas Tree

```
If you have a *small* word list, then you can run a regex scan on the whole word list. Convert the query string into a regex and you're good to go.

Otherwise, you can organize the word list in chunks, e.g. the equivalent of splitting it into several files in different directories:

```
Appl => [ Apple ]
Chri => [ Christchurch, Christmas Tree, ... ]
Shop => [ Shopper, Shopping Bag, Shopkeeper, ]

```

(You can have several levels).

Since your search query seems to be *anchored*, i.e. you know it starts at the word's beginning, when you look for "???i???as ?r??" you see that "???i" will only match "Chri", and only look in that sub-list.

(Actually if you have to do this a lot of times, you'll better build a recursive search and organize the list as a [n- or "m-ary" tree](https://en.wikipedia.org/wiki/M-ary_tree) - here are some [examples](https://www.ics.uci.edu/~brgallar/week6_3.html)).