Solution Exercise 28

Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n

#Solution using a "traditional approach"
def filter_long_words1(list_of_words, n):
    filtered_list = []
    for word in list_of_words:
        if len(word) > n:
            filtered_list.append(word)
    return filtered_list

#Solution using list comprehension
def filter_long_words2(list_of_words, n):
    return [word for word in list_of_words if len(word) > n]

def main():
    word_list = ["Alpha", "Beta", "Gamma", "Delta"]
    print(filter_long_words1(word_list, 4))
    print(filter_long_words2(word_list, 4))
       
if __name__ == '__main__':
    main()