Indices#

navground.learning.indices

Generic type of the items in a sequence or dict

A union type that can be used to get a part of a sequence or of a dictionary with integer keys.

  • Indices.all -> select all items

  • set -> select the items with indices in the set

  • slice -> select the items covered by the slide.

For example:

>>> Indices.all().sub_sequence([1, 2, 3])
[1, 2, 3]
>>> Indices.all().sub_dict({1: 2, 3: 4, 5: 6})
{1: 2, 3: 4, 5: 6}
>>> Indices({0, 2}).sub_sequence((1, 2, 3))
(1, 3)
>>> Indices({0, 2}).sub_dict({1: 2, 3: 4, 5: 6})
{}
>>> Indices(slice(-2, None)).sub_sequence((1, 2, 3, 4, 5))
(4, 5)
>>> Indices(slice(1, 3)).sub_dict({1: 2, 3: 4, 5: 6})
{1: 2}
Parameters:

value (IndicesLike) – The value - "ALL": initializes Indices.all - set: initializes the indices from the set - slice: initializes the indices from the slide. - Indices: copy the value

Indices that covers all the items.

Return type:

Indices

Covert to a set of the indices. Uses length to evaluate slices using slice.indices().

Parameters:

length (int) – The maximal length of the sequence

Returns:

the set of indices

Return type:

set[int]

Read the indices from the representation asdict.

Parameters:

rs (Mapping[str, Any]) – The dictionart

Returns:

The indices

Raises:

ValueError – if no conversion is possible

Return type:

Indices

Intersects with another set of indices.

Parameters:
  • other (Indices) – The other set

  • length (int) – The maximal length of the sequences, used to evaluate slices.

Returns:

The set of indices that are common to both sets.

Return type:

Indices

Extracts a sub-set.

Parameters:

xs (dict[int, T]) – The original sequence

Returns:

the items of xs covered by the indices

Return type:

dict[int, T]

Extracts a sub-sequence.

Parameters:

xs (Sequence[T]) – The original sequence

Returns:

the items of xs covered by the indices

Return type:

Sequence[T]

A JSON-able representation.

Returns:

A JSON-able dict

The lowest index

Returns:

The lowest index if the available, else None.