0
0
DSA Pythonprogramming~10 mins

Why Strings Are a Data Structure Not Just Text in DSA Python - Test Your Knowledge

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

Complete the code to get the first character of the string.

DSA Python
word = "hello"
first_char = word[1]
Drag options to blanks, or click blank then click option'
A<0>
B(0)
C[0]
D{0}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets
Starting index at 1
2fill in blank
medium

Complete the code to find the length of the string.

DSA Python
word = "hello"
length = [1](word)
Drag options to blanks, or click blank then click option'
Alength
Bsize
Ccount
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like size() or length()
3fill in blank
hard

Fix the error in the code to get the last character of the string.

DSA Python
word = "hello"
last_char = word[1]
Drag options to blanks, or click blank then click option'
A[1]
B[-1]
C[5]
D[-5]
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive indexes beyond string length
Using index 1 which is the second character
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values.

DSA Python
words = ["apple", "banana", "cherry"]
lengths = {word[1] for word in words if len(word) [2] 5}
Drag options to blanks, or click blank then click option'
A: len(word)
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in dictionary comprehension
Using wrong comparison operators
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, filtering words longer than 5.

DSA Python
words = ["apple", "banana", "cherry"]
result = { [1]: [2] for word in words if len(word) [3] 5 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase keys
Using wrong comparison operators