A shared folder with AI prompts and code snippets
From workspace: FreeCodeCamp
Team: Main
Total snippets: 6
6 snippets
Replace all vowels in words using nested list comprehension and join.
sentence = "code with python" vowels = 'aeiou' masked = [''.join(['*' if ch in vowels else ch for ch in word]) for word in sentence.split()] print(masked) # ['c*d*', 'w*th', 'pyth*n']
Reverse characters in each word using slicing inside list comprehension.
sentence = "list comprehension python" reversed_words = [word[::-1] for word in sentence.split()] print(reversed_words) # ['tsil', 'noisneherpmoc', 'nohtyp']
Return only words longer than 4 characters using list comprehension.
sentence = "this is a list comprehension demo" filtered = [word for word in sentence.split() if len(word) > 4] print(filtered) # ['list', 'comprehension']
Flip case of each word using .swapcase() in list comprehension.
sentence = "HeLLo WoRLD" toggled = [word.swapcase() for word in sentence.split()] print(toggled) # ['hEllO', 'wOrld']
Convert each word to title case using list comprehension.
sentence = "hello world from python" titled = [word.title() for word in sentence.split()] print(titled) # ['Hello', 'World', 'From', 'Python']
Use list comprehension to convert all words in a sentence to uppercase.
sentence = "hello world from python" uppercased = [word.upper() for word in sentence.split()] print(uppercased) # ['HELLO', 'WORLD', 'FROM', 'PYTHON']