CyclicTuple

class datastructuretools.CyclicTuple

A cylic tuple.

Example 1. Initializes from string:

>>> cyclic_tuple = datastructuretools.CyclicTuple('abcd')
>>> cyclic_tuple
CyclicTuple(['a', 'b', 'c', 'd'])
>>> for x in range(8):
...     print(x, cyclic_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.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "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]; "builtins.tuple" [color=2, group=1, label=tuple, shape=box]; "builtins.object" -> "builtins.tuple"; } "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" -> "abjad.tools.datastructuretools.CyclicTuple.CyclicTuple"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; "builtins.tuple" -> "abjad.tools.datastructuretools.CyclicTuple.CyclicTuple"; }

Bases

Attribute summary

count(...)
index((value, [start, ...) Raises ValueError if the value is not present.
__add__ Return self+value.
__contains__ Return key in self.
__copy__(\*args) Copies Abjad value object.
__eq__(expr) Is true when expr is a tuple with items equal to those of this cyclic tuple.
__format__([format_specification]) Formats Abjad object.
__ge__ Return self>=value.
__getitem__(i) Gets i from cyclic tuple.
__getslice__(start_index, stop_index) Gets slice of items from start_index to stop_index in cyclic tuple.
__gt__ Return self>value.
__hash__() Hashes cyclic tuple.
__iter__ Implement iter(self).
__le__ Return self<=value.
__len__ Return len(self).
__lt__ Return self<value.
__mul__ Return self*value.n
__ne__(expr) Is true when Abjad object does not equal expr.
__new__ Create and return a new object.
__repr__() Gets interpreter representation of Abjad object.
__rmul__ Return self*value.
__str__() String representation of cyclic tuple.

Methods

(tuple).count(value) → integer -- return number of occurrences of value
(tuple).index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

Special methods

(tuple).__add__()

Return self+value.

(tuple).__contains__()

Return key in self.

(AbjadValueObject).__copy__(*args)

Copies Abjad value object.

Returns new Abjad value object.

CyclicTuple.__eq__(expr)

Is true when expr 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.

(tuple).__ge__()

Return self>=value.

CyclicTuple.__getitem__(i)

Gets i from cyclic tuple.

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

Returns item.

CyclicTuple.__getslice__(start_index, stop_index)

Gets slice of items from start_index to stop_index in cyclic tuple.

Gets slice open at right:

>>> sequence = [0, 1, 2, 3, 4, 5]
>>> sequence = datastructuretools.CyclicTuple(sequence)
>>> sequence[2:]
(2, 3, 4, 5)

Gets slice closed at right:

>>> sequence = [0, 1, 2, 3, 4, 5]
>>> sequence = datastructuretools.CyclicTuple(sequence)
>>> sequence[:15]
(0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2)

Returns tuple.

(tuple).__gt__()

Return self>value.

CyclicTuple.__hash__()

Hashes cyclic tuple.

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

Returns integer.

(tuple).__iter__()

Implement iter(self).

(tuple).__le__()

Return self<=value.

(tuple).__len__()

Return len(self).

(tuple).__lt__()

Return self<value.

(tuple).__mul__()

Return self*value.n

(AbjadObject).__ne__(expr)

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

Returns true or false.

(tuple).__new__()

Create and return a new object. See help(type) for accurate signature.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(tuple).__rmul__()

Return self*value.

CyclicTuple.__str__()

String representation of cyclic tuple.

Returns string.