0
0
Prompt Engineering / GenAIml~10 mins

Contextual compression in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple function that compresses text by removing vowels.

Prompt Engineering / GenAI
def compress_text(text):
    vowels = 'aeiouAEIOU'
    return ''.join(char for char in text if [1])
Drag options to blanks, or click blank then click option'
Achar.isdigit()
Bchar not in vowels
Cchar in vowels
Dchar == ' '
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'char in vowels' will keep vowels instead of removing them.
2fill in blank
medium

Complete the code to calculate the compression ratio of original and compressed text lengths.

Prompt Engineering / GenAI
def compression_ratio(original, compressed):
    return len(compressed) / [1]
Drag options to blanks, or click blank then click option'
Alen(original) - len(compressed)
Blen(compressed)
Clen(original) + len(compressed)
Dlen(original)
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by compressed length instead of original length.
3fill in blank
hard

Fix the error in the function that compresses text by replacing spaces with underscores.

Prompt Engineering / GenAI
def compress_spaces(text):
    return text.replace(' ', [1])
Drag options to blanks, or click blank then click option'
A' '
B'-'
C'_'
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty string '' removes spaces instead of replacing them.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their compressed forms by removing vowels.

Prompt Engineering / GenAI
compressed_dict = {word: ''.join(char for char in word if [1]) for word in words if [2]
Drag options to blanks, or click blank then click option'
Achar not in 'aeiouAEIOU'
Bchar in 'aeiouAEIOU'
Clen(word) > 3
Dlen(word) < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'char in vowels' keeps vowels instead of removing them.
Filtering words shorter than 3 instead of longer.
5fill in blank
hard

Fill all three blanks to create a function that compresses text by removing vowels, replacing spaces with underscores, and calculating compression ratio.

Prompt Engineering / GenAI
def full_compress(text):
    no_vowels = ''.join(char for char in text if [1])
    replaced = no_vowels.replace(' ', [2])
    ratio = len(replaced) / [3]
    return replaced, ratio
Drag options to blanks, or click blank then click option'
Achar not in 'aeiouAEIOU'
B'_'
Clen(text)
D' '
Attempts:
3 left
💡 Hint
Common Mistakes
Replacing spaces with spaces instead of underscores.
Dividing by compressed length instead of original length.