def do_stuff(text): words = text.split(' ') # Convert all words to lowercase words = [word.lower() for word in words] # Trim spaces (though split already handles this well) words = [word.strip() for word in words] # Reverse the word order words.reverse() # Filter words with length greater than 5 long_words = [word for word in words if len(word) > 5] # Join the words with ', ' result = ', '.join(long_words) return result # Example usage text = "Hello world programming is amazing and beautiful" output = do_stuff(text) print(output)