CyclicTuple

class datastructuretools.CyclicTuple(items=None)

Cylic tuple.

>>> import abjad

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.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.CyclicTuple.CyclicTuple" [color=black, fontcolor=white, group=2, label=<<B>CyclicTuple</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.CyclicTuple.CyclicTuple"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

items Gets items in cyclic tuple.
__contains__(item) Is true when cyclic tuple contains item.
__eq__(argument) Is true when argument is a tuple with items equal to those of this cyclic tuple.
__format__([format_specification]) Formats Abjad object.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes cyclic tuple.
__iter__() Iterates cyclic tuple.
__len__() Gets length of cyclic tuple.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.
__str__() Gets string representation of cyclic tuple.

Read-only properties

CyclicTuple.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)

Returns tuple.

Special methods

CyclicTuple.__contains__(item)

Is true when cyclic tuple contains item.

Returns true or false.

CyclicTuple.__eq__(argument)

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

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

CyclicTuple.__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.

Returns item.

CyclicTuple.__hash__()

Hashes cyclic tuple.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

CyclicTuple.__iter__()

Iterates cyclic tuple.

Iterates items only once.

Does not iterate infinitely.

CyclicTuple.__len__()

Gets length of cyclic tuple.

Returns nonnegative integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

CyclicTuple.__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)'

Returns string.