Views Module¶
Module: piethorn.collections.views
Overview¶
This module provides read-only wrappers over sequences and mappings.
SequenceView¶
- class SequenceView(origin, *, reverse=False, cut=None)¶
Read-only view over an existing sequence.
Main properties¶
origin_sizeLength of the original sequence.
is_reversedWhether iteration is reversed.
parent/has_parentParent view information for nested views.
cut/has_cutNormalized slice applied to the origin.
Example¶
from piethorn.collections.views import SequenceView view = SequenceView([1, 2, 3, 4], reverse=True, cut=slice(1, 4)) nested = view[1:] list(view) # [4, 3, 2] view[1] # 3 list(nested) # [3, 2]
Methods¶
count(value)Count occurrences in the visible region.
index(value, start=0, stop=None)Return the view-local index of a value.