CyclicTuple

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=1]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/utilities/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; } subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=2]; "abjad.utilities.CyclicTuple.CyclicTuple" [URL="../api/abjad/utilities/CyclicTuple.html#abjad.utilities.CyclicTuple.CyclicTuple", color=black, fontcolor=white, label="Cyclic\nTuple", target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.utilities.CyclicTuple.CyclicTuple"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; }

class abjad.utilities.CyclicTuple.CyclicTuple(items=None)

Cyclic tuple.

Initializes from string:

>>> tuple_ = abjad.CyclicTuple('abcd')
>>> tuple_
CyclicTuple(['a', 'b', 'c', 'd'])
>>> for x in range(8):
...     print(x, tuple_[x])
...
0 a
1 b
2 c
3 d
4 a
5 b
6 c
7 d

Cyclic tuples overload the item-getting method of built-in tuples.

Cyclic tuples return a value for any integer index.

Cyclic tuples otherwise behave exactly like built-in tuples.


Attributes Summary

__contains__ Is true when cyclic tuple contains item.
__eq__ Is true when argument is a tuple with items equal to those of this cyclic tuple.
__getitem__ Gets item or slice identified by argument.
__hash__ Hashes cyclic tuple.
__iter__ Iterates cyclic tuple.
__len__ Gets length of cyclic tuple.
__str__ Gets string representation of cyclic tuple.
items Gets items in cyclic tuple.

Special methods

__contains__(item)

Is true when cyclic tuple contains item.

Return type:bool
__eq__(argument)

Is true when argument is a tuple with items equal to those of this cyclic tuple.

Return type:bool
(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

__getitem__(argument)

Gets item or slice identified by argument.

Gets slice open at right:

>>> items = [0, 1, 2, 3, 4, 5]
>>> tuple_ = abjad.CyclicTuple(items=items)
>>> tuple_[2:]
(2, 3, 4, 5)

Gets slice closed at right:

>>> items = [0, 1, 2, 3, 4, 5]
>>> tuple_ = abjad.CyclicTuple(items=items)
>>> tuple_[:15]
(0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2)

Raises index error when argument can not be found in cyclic tuple.

Return type:Any
__hash__()

Hashes cyclic tuple.

Redefined in tandem with __eq__.

Return type:int
__iter__()

Iterates cyclic tuple.

Iterates items only once.

Does not iterate infinitely.

Return type:Iterator[+T_co]
__len__()

Gets length of cyclic tuple.

Return type:int
(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

__str__()

Gets string representation of cyclic tuple.

Gets string:

>>> str(abjad.CyclicTuple('abcd'))
'(a, b, c, d)'

Gets string:

>>> str(abjad.CyclicTuple([1, 2, 3, 4]))
'(1, 2, 3, 4)'
Return type:str

Read-only properties

items

Gets items in cyclic tuple.

Gets items:

>>> tuple_ = abjad.CyclicTuple('abcd')
>>> tuple_.items
('a', 'b', 'c', 'd')

Gets items:

>>> tuple_ = abjad.CyclicTuple([1, 2, 3, 4])
>>> tuple_.items
(1, 2, 3, 4)
Return type:Tuple