0
0
LangChainframework~20 mins

Code-aware text splitting in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Code Splitting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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))
A2
B3
C1
D4
Attempts:
2 left
💡 Hint
Think about how the splitter respects code boundaries and chunk size.
📝 Syntax
intermediate
1: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?
Asplitter = CodeTextSplitter(lang='python')
Bsplitter = CodeTextSplitter(language='py')
Csplitter = CodeTextSplitter(language='python')
Dsplitter = CodeTextSplitter(language='Python')
Attempts:
2 left
💡 Hint
Check the exact parameter name and accepted language string.
🔧 Debug
advanced
2: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)
ABecause split_text expects a string, but an integer was passed
BBecause chunk_size must be a string, not an integer
CBecause CodeTextSplitter requires a language parameter
DBecause split_text is not a method of CodeTextSplitter
Attempts:
2 left
💡 Hint
Check the type of the argument passed to split_text.
state_output
advanced
2: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])
Adef greet(name):\n print(f"Hello, {name}!")\n\n
Bdef greet(name):\n print(f"Hello, {name}!")\n\ngreet('Alice')
Cdef greet(name):\n print(f"Hello, {name}!")
Ddef greet(name):\n print(f"Hello, {name}!")\n\ngreet('Al'
Attempts:
2 left
💡 Hint
Remember chunk size and overlap affect how much text is included.
🧠 Conceptual
expert
2: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?
AIt automatically converts code to pseudocode for easier understanding
BIt splits text faster by ignoring whitespace and comments
CIt compresses code chunks to reduce size for storage
DIt splits code respecting syntax and structure, preventing broken code blocks in chunks
Attempts:
2 left
💡 Hint
Think about how code structure affects splitting.