droplastn() — langchain Function Reference
Architecture documentation for the droplastn() function in list.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f91d2284_c18b_537d_db04_d69b6ec85ef7["droplastn()"] 39460b97_96ad_60ff_34e4_145e3ec6b305["list.py"] f91d2284_c18b_537d_db04_d69b6ec85ef7 -->|defined in| 39460b97_96ad_60ff_34e4_145e3ec6b305 f80a51cd_11c2_9fd1_6239_43804a539ce4["_transform()"] f80a51cd_11c2_9fd1_6239_43804a539ce4 -->|calls| f91d2284_c18b_537d_db04_d69b6ec85ef7 737ee74b_6bba_9e83_2e9f_425453da49b1["_atransform()"] 737ee74b_6bba_9e83_2e9f_425453da49b1 -->|calls| f91d2284_c18b_537d_db04_d69b6ec85ef7 style f91d2284_c18b_537d_db04_d69b6ec85ef7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/output_parsers/list.py lines 23–40
def droplastn(
iter: Iterator[T], # noqa: A002
n: int,
) -> Iterator[T]:
"""Drop the last `n` elements of an iterator.
Args:
iter: The iterator to drop elements from.
n: The number of elements to drop.
Yields:
The elements of the iterator, except the last n elements.
"""
buffer: deque[T] = deque()
for item in iter:
buffer.append(item)
if len(buffer) > n:
yield buffer.popleft()
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does droplastn() do?
droplastn() is a function in the langchain codebase, defined in libs/core/langchain_core/output_parsers/list.py.
Where is droplastn() defined?
droplastn() is defined in libs/core/langchain_core/output_parsers/list.py at line 23.
What calls droplastn()?
droplastn() is called by 2 function(s): _atransform, _transform.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free