Challenge - 5 Problems
Nested List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested list indexing
What is the output of the following R code?
R Programming
nested_list <- list(a = list(1, 2, 3), b = list(4, 5, 6)) result <- nested_list$a[[2]] print(result)
Attempts:
2 left
💡 Hint
Remember that [[ ]] extracts the element itself, not a sublist.
✗ Incorrect
nested_list$a is a list of three elements: 1, 2, 3. Using [[2]] extracts the second element, which is 2.
❓ Predict Output
intermediate2:00remaining
Length of nested list element
What is the value of length(nested_list$b) after running this code?
R Programming
nested_list <- list(a = list(1, 2, 3), b = list(4, 5, 6)) length(nested_list$b)
Attempts:
2 left
💡 Hint
length() returns the number of elements in the list, not the sum of elements.
✗ Incorrect
nested_list$b is a list with three elements: 4, 5, and 6, so length is 3.
❓ Predict Output
advanced2:00remaining
Output of nested list modification
What is the output of this R code?
R Programming
nested_list <- list(a = list(1, 2), b = list(3, 4)) nested_list$a[[2]] <- 10 print(nested_list$a)
Attempts:
2 left
💡 Hint
Using [[ ]] allows you to replace the element inside the nested list.
✗ Incorrect
The second element of nested_list$a is replaced by 10. Printing nested_list$a shows the list with elements 1 and 10.
❓ Predict Output
advanced2:00remaining
Accessing deeply nested list element
What is the output of this code?
R Programming
nested_list <- list(x = list(y = list(z = 42))) print(nested_list$x$y$z)
Attempts:
2 left
💡 Hint
Use $ to access named elements inside nested lists.
✗ Incorrect
nested_list$x$y$z accesses the value 42 stored deeply inside the nested list.
🧠 Conceptual
expert2:00remaining
Number of elements in a nested list
Given the nested list below, how many top-level elements does it have?
R Programming
nested_list <- list(alpha = list(1, 2), beta = list(3, 4), gamma = 5)
Attempts:
2 left
💡 Hint
Count only the elements directly inside nested_list, not inside sublists.
✗ Incorrect
nested_list has three top-level elements named alpha, beta, and gamma.