0
0
Prompt Engineering / GenAIml~10 mins

Data extraction from text 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 extract all email addresses from the text using a regular expression.

Prompt Engineering / GenAI
import re
text = "Contact us at support@example.com or sales@example.org"
emails = re.findall([1], text)
print(emails)
Drag options to blanks, or click blank then click option'
A"[a-z]+"
B"[0-9]+"
C"\d{3}-\d{2}-\d{4}"
D"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a regex that matches only numbers or unrelated patterns.
2fill in blank
medium

Complete the code to extract all dates in the format YYYY-MM-DD from the text.

Prompt Engineering / GenAI
import re
text = "The event is on 2024-06-15 and registration ends 2024-05-30."
dates = re.findall([1], text)
print(dates)
Drag options to blanks, or click blank then click option'
A"\d{2}/\d{2}/\d{4}"
B"\d{4}-\d{2}-\d{2}"
C"[a-zA-Z]+ \d{1,2}, \d{4}"
D"\d{4}/\d{2}/\d{2}"
Attempts:
3 left
💡 Hint
Common Mistakes
Using slashes instead of dashes or wrong digit counts.
3fill in blank
hard

Fix the error in the code to extract phone numbers in the format (XXX) XXX-XXXX.

Prompt Engineering / GenAI
import re
text = "Call me at (123) 456-7890 or (987) 654-3210."
phones = re.findall([1], text)
print(phones)
Drag options to blanks, or click blank then click option'
A"\(\d{3}\) \d{3}-\d{4}"
B"\d{3}-\d{3}-\d{4}"
C"\(\d{3}\)\d{3}-\d{4}"
D"\d{10}"
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping parentheses or missing the space after them.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their lengths from the text, including only words longer than 4 letters.

Prompt Engineering / GenAI
text = "Machine learning extracts useful data from text"
words = text.split()
lengths = { [1] : [2] for word in words if len(word) > 4 }
print(lengths)
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.upper()
Dlen(text)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole text length or uppercase words as keys or values.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths, including only words with length greater than 3.

Prompt Engineering / GenAI
text = "Data extraction from text is useful"
words = text.split()
result = { [1] : [2] for word in words if [3] }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase words as keys or wrong filter conditions.