def right_words(list, num): result = [] #iterating through the list and stating the condition that length of values in list must be equal to num for it to append to the result list, we have: for values in list: if len(values) == num: result.append(values) return result print(right_words(["cat", "heart", "ace", "bean"], 3))