from typing import List
import random


def get_words_with_ngrams(
    ngrams: List[str],
    word_list: List[str],
    shuffle_words: bool = True,
) -> List[str]:
    """Filters a list of words based on whether any ngram is contained in the word."""
    relevant_words = []

    # remove duplicate ngrams
    ngrams = list(set(ngrams))

    for word in word_list:
        for ngram in ngrams:
            if ngram in word:
                relevant_words.append(word)

    # remove duplicate words
    relevant_words = list(set(relevant_words))

    if shuffle_words:
        random.shuffle(relevant_words)

    return relevant_words