def find_ngrams(single_words, n):
    """
    Args:
        single_words: list of words in the text, in the order they appear in the text
            all words are made of lowercase characters
        n:            length of 'n-gram' window
    Returns:
        list of n-grams from input text list, or an empty list if n is not a valid value
    """
    ngrams = []
    if n <= 0 or n > len(single_words):
        return ngrams
        #returns empty list
    elif n == 1:
        return single_words
        #returns original input
    else:
        for i in range(len(single_words)):
            if n + i > len(single_words):
                break
                #done so that the very last word of the n-gram is the
                #very last word of the list single_words
            else:
                mini_list = single_words[i:n+i]
                #creates a list with the words in the ngram
                #the list contains the words between index i and n+i so that 
                #the maximum possible value of n+i is the length of single_words
                ngrams_word = ' '.join([str(item) for item in mini_list])
                #the list is transformed into a string with spaces in between
                #and no spaces at the beginning or end
                ngrams.append(ngrams_word)
                #the n-gram string is added to the list
        return ngrams