Challenge - 5 Problems
Code Splitting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this LangChain code-aware text splitter?
Given the following Python code using LangChain's
CodeTextSplitter, what will be the length of the resulting list chunks after splitting the code_text?LangChain
from langchain.text_splitter import CodeTextSplitter code_text = '''def add(a, b):\n return a + b\n\nprint(add(2, 3))\n''' splitter = CodeTextSplitter(chunk_size=20, chunk_overlap=0) chunks = splitter.split_text(code_text) print(len(chunks))
Attempts:
2 left
💡 Hint
Think about how the splitter respects code boundaries and chunk size.
✗ Incorrect
The CodeTextSplitter splits the code into chunks of max 20 characters without overlap. The given code is split into 3 chunks because it respects code structure and line breaks.
📝 Syntax
intermediate1:30remaining
Which option correctly initializes a CodeTextSplitter with Python language support?
You want to create a
CodeTextSplitter that understands Python code syntax. Which of the following code snippets correctly initializes it?Attempts:
2 left
💡 Hint
Check the exact parameter name and accepted language string.
✗ Incorrect
The correct parameter is 'language' with the value 'python' in lowercase. Other options use incorrect parameter names or values.
🔧 Debug
advanced2:00remaining
Why does this code-aware splitter raise an error?
Consider this code snippet using LangChain's CodeTextSplitter:
from langchain.text_splitter import CodeTextSplitter splitter = CodeTextSplitter(chunk_size=50) chunks = splitter.split_text(12345)Why does this code raise an error?
LangChain
from langchain.text_splitter import CodeTextSplitter splitter = CodeTextSplitter(chunk_size=50) chunks = splitter.split_text(12345)
Attempts:
2 left
💡 Hint
Check the type of the argument passed to split_text.
✗ Incorrect
The split_text method expects a string input to split. Passing an integer causes a TypeError.
❓ state_output
advanced2:00remaining
What is the content of the first chunk after splitting?
Given this Python code snippet using LangChain's CodeTextSplitter:
code = '''def greet(name):\n print(f"Hello, {name}!")\n\ngreet('Alice')\n'''
splitter = CodeTextSplitter(chunk_size=30, chunk_overlap=5)
chunks = splitter.split_text(code)
print(chunks[0])
What will be printed as the first chunk?LangChain
code = '''def greet(name): print(f"Hello, {name}!") greet('Alice') ''' splitter = CodeTextSplitter(chunk_size=30, chunk_overlap=5) chunks = splitter.split_text(code) print(chunks[0])
Attempts:
2 left
💡 Hint
Remember chunk size and overlap affect how much text is included.
✗ Incorrect
The first chunk includes the function definition and the newline after it, fitting within 30 characters with 5 characters overlap.
🧠 Conceptual
expert2:30remaining
Why use a code-aware text splitter instead of a simple character splitter?
Which of the following best explains the advantage of using a code-aware text splitter like LangChain's
CodeTextSplitter over a simple character-based splitter?Attempts:
2 left
💡 Hint
Think about how code structure affects splitting.
✗ Incorrect
Code-aware splitters understand code syntax and avoid splitting inside code blocks, which keeps chunks meaningful and runnable.