0
0
Data Structures Theoryknowledge~10 mins

String matching basics in Data Structures Theory - Interactive Code Practice

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

Complete the code to find if the substring exists in the main string.

Data Structures Theory
if "needle" [1] "haystack":
    print("Found")
Drag options to blanks, or click blank then click option'
A==
Bnot in
Cin
Dcontains
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using '==' instead of 'in' to check substring presence.
2fill in blank
medium

Complete the code to get the starting index of the substring in the main string.

Data Structures Theory
index = "haystack".[1]("needle")
Drag options to blanks, or click blank then click option'
Afind
BindexOf
Clocate
Dsearch
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using methods that don't exist in Python like 'indexOf'.
3fill in blank
hard

Fix the error in the code to correctly check if the substring is not in the main string.

Data Structures Theory
if "needle" [1] "haystack":
    print("Not found")
Drag options to blanks, or click blank then click option'
Ain
Bnot in
C!=
Dis not
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using '!=' which compares equality, not substring presence.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

Data Structures Theory
{word: [1] for word in words if [2] > 3}
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Dword.length
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'word.length' which is not valid in Python.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if the length is less than 5.

Data Structures Theory
{ [1]: [2] for word in words if [3] < 5 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Dword
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'word' instead of 'word.upper()' for keys.