0
0
DSA Pythonprogramming~10 mins

Get Length of Linked List 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 initialize the length counter to zero.

DSA Python
def get_length(head):
    length = [1]
    current = head
    while current:
        length += 1
        current = current.next
    return length
Drag options to blanks, or click blank then click option'
A0
B1
Chead
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Starting length at 1 instead of 0
Setting length to None
Assigning length to head
2fill in blank
medium

Complete the code to move to the next node in the linked list.

DSA Python
def get_length(head):
    length = 0
    current = head
    while current:
        length += 1
        current = [1]
    return length
Drag options to blanks, or click blank then click option'
Ahead.next
Bcurrent
Ccurrent.next
Dlength.next
Attempts:
3 left
💡 Hint
Common Mistakes
Using head.next instead of current.next
Assigning current to itself causing infinite loop
Using length.next which is invalid
3fill in blank
hard

Fix the error in the loop condition to correctly check if the current node exists.

DSA Python
def get_length(head):
    length = 0
    current = head
    while [1]:
        length += 1
        current = current.next
    return length
Drag options to blanks, or click blank then click option'
Acurrent == None
Bcurrent is not None
Chead
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'current == None' which is less preferred
Using 'head' which does not change in the loop
Using 'length' which is an integer
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths for words longer than 3 characters.

DSA Python
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'
Using 'word' instead of 'len(word)'
Not filtering words by length
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than zero.

DSA Python
data = {'a': 1, 'b': 0, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' for keys
Using '<' instead of '>' for filtering
Including values equal to zero