IndexSet1D#

class IndexSet1D(iterable=None, /, *, name=None)#

Custom list-like data structure to define index-sets with 1-dim scalar elements.

Requires all elements to be unique scalars (such as int, str, Timestamp, etc.). Supports all mutable sequence operations from builtins.list and rich comparisons from builtins.set.

Parameters:
iterableiterable, optional

Input data to be encapsulated in the IndexSet.

namestr, optional

Name to refer to 1-dim scalar elements - not used internally, and solely for user reference.

Raises:
TypeError

If the input contains non-scalar element(s) (any iterable except string).

ValueError

If the input includes (or creates) duplicate elements.

See also

IndexSetND

For N-dim tuple elements.

Examples

Constructing empty to populate later:

>>> IndexSet1D()
IndexSet1D:
[]

Constructing with an iterable:

>>> IndexSet1D(range(3))
IndexSet1D:
[0, 1, 2]
>>> IndexSet1D(['Delhi', 'Seattle', 'Tokyo'], name='CITY')
IndexSet1D: (CITY)
['Delhi', 'Seattle', 'Tokyo']

Methods

IndexSet1D.append(elem, /)

Append an element to the end of the IndexSet, in-place.

IndexSet1D.clear()

Remove all elements from the IndexSet.

IndexSet1D.extend(elems, /)

Extend the IndexSet by appending elements from an iterable, in-place.

IndexSet1D.index(elem[, start, end])

Get the position index of an element in the IndexSet.

IndexSet1D.insert(index, elem, /)

Insert an element at a position index in the IndexSet.

IndexSet1D.pop([index])

Remove and return the element at a position index in the IndexSet.

IndexSet1D.remove(elem, /)

Remove an element from the IndexSet, in-place.

IndexSet1D.reverse()

Reverse the order of elements of the IndexSet, in-place.

IndexSet1D.sort(*[, key, reverse])

Sort the IndexSet in ascending order, in-place.

Attributes

IndexSet1D.name

Name to refer to 1-dim scalar elements.