0
0
DSA Pythonprogramming~10 mins

Substring Search Patterns in DSA Python - Interactive Practice

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

Complete the code to check if the pattern exists in the text using the 'in' keyword.

DSA Python
text = "hello world"
pattern = "world"
if pattern [1] text:
    print("Pattern found")
else:
    print("Pattern not found")
Drag options to blanks, or click blank then click option'
Anot in
Bin
C==
Dis
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'in' to check substring.
Using 'is' which checks object identity, not substring.
2fill in blank
medium

Complete the code to find the first index of the pattern in the text using the find() method.

DSA Python
text = "abracadabra"
pattern = "cad"
index = text.[1](pattern)
print(index)
Drag options to blanks, or click blank then click option'
Afind
Bindex
Csearch
Dlocate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' which raises an error if substring not found.
Using non-existent methods like 'search' or 'locate'.
3fill in blank
hard

Fix the error in the code to correctly count occurrences of the pattern in the text.

DSA Python
text = "banana"
pattern = "ana"
count = text.[1](pattern)
print(count)
Drag options to blanks, or click blank then click option'
Afind
Bindex
Ccount
Dsearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() which returns only the first index.
Using index() which raises error if substring not found.
4fill in blank
hard

Fill both blanks to create a dictionary of patterns and their counts from a list of words.

DSA Python
words = ["apple", "banana", "apple", "cherry"]
pattern_counts = {word: words.[1](word) for word in words if "a" [2] word}
print(pattern_counts)
Drag options to blanks, or click blank then click option'
Acount
Bfind
Cin
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() instead of count() for counting.
Using 'not in' instead of 'in' to filter words.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase patterns and their first index in text if found.

DSA Python
text = "hello world"
patterns = ["he", "wo", "or"]
result = {pattern.[1](): text.[2](pattern) for pattern in patterns if text.[3](pattern) != -1}
print(result)
Drag options to blanks, or click blank then click option'
Aupper
Bfind
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() instead of find() for index.
Using upper() incorrectly or missing it.