textflint.input_layer.component.field.list_field

List Field Class

A helper class that represents input list values that to be modified.

class textflint.input_layer.component.field.list_field.ListField(field_value, **kwargs)[source]

Bases: textflint.input_layer.component.field.field.Field

A helper class that represents input list values that to be modified.

Operations which modify field_value would generate new Field instance.

__init__(field_value, **kwargs)[source]
Parameters

field_value ([str]) – The list that ListField represents.

replace_at_indices(indices, new_items)[source]

Replace items at indices.

Notice: just support isometric replace.

Parameters
  • indices (list[int|list|slice]) – each index can be int indicate replace single item or their list like [1, 2, 3]. each index can be list like (0,3) indicate replace items from 0 to 3(not included) or their list like [(0, 3), (5,6)] each index can be slice which would be convert to list.

  • new_items (list) – items corresponding indices.

Returns

new field object.

replace_at_index(index, new_items)[source]

Replace item at index.

Parameters
  • index (int|list|slice) –

    can be int indicate replace single item or their list like [1, 2, 3] can be list like (0,3) indicate replace items from 0

    to 3(not included) or their list like [(0, 3), (5,6)]

    can be slice which would be convert to list.

  • new_items (list) – items corresponding index.

Returns

new field object.

delete_at_indices(indices)[source]

Delete items at indices.

Parameters

indices (list[int|list|slice]) – each index can be int indicate delete single item or their list like [1, 2, 3]. each index can be list like (0,3) indicate replace items from 0 to 3(not included) or their list like [(0, 3), (5,6)] each index can be slice which would be convert to list.

Returns

new field object.

delete_at_index(index)[source]

Delete item at index.

Parameters

index (int|list|slice) –

can be int indicate delete single item or their list like [1, 2, 3] can be list like (0,3) indicate replace items from 0

to 3(not included) or their list like [(0, 3), (5,6)]

can be slice which would be convert to list.

Returns

new field object.

insert_before_indices(indices, new_items)[source]

Insert items before indices.

Parameters
  • indices (list[int|list|slice]) – each index can be int indicate insert single item or their list like [1, 2, 3]. each index can be list like (0,3) indicate replace items from 0 to 3(not included) or their list like [(0, 3), (5,6)] each index can be slice which would be convert to list.

  • new_items (list) – items corresponding indices.

Returns

new field object.

insert_before_index(index, new_items)[source]

Insert items before index.

Parameters
  • index (int|list|slice) –

    can be int indicate insert single item or their list like [1, 2, 3] can be list like (0,3) indicate replace items from 0

    to 3(not included) or their list like [(0, 3), (5,6)]

    can be slice which would be convert to list.

  • new_items (list) – items corresponding index.

Returns

new field object.

insert_after_indices(indices, new_items)[source]

Insert item after index.

Parameters
  • indices (list[int|list|slice]) – each index can be int indicate insert single item or their list like [1, 2, 3]. each index can be list like (0,3) indicate replace items from 0 to 3(not included) or their list like [(0, 3), (5,6)] each index can be slice which would be convert to list.

  • new_items (list) – items corresponding indices.

Returns

new field object.

insert_after_index(index, new_items)[source]

Insert item after index.

Parameters
  • index (int|list|slice) –

    can be int indicate insert single item or their list like [1, 2, 3] can be list like (0,3) indicate replace items from 0

    to 3(not included) or their list like [(0, 3), (5,6)]

    can be slice which would be convert to list.

  • new_items (list) – items corresponding index

Returns

new field object.

swap_at_index(first_index, second_index)[source]

Swap item between first_index and second_index.

Parameters
  • first_index (int) – index of first item

  • second_index (int) – index of second item

Returns

new field object.