infineac.helper.add_context_integers#

infineac.helper.add_context_integers(lst: list[int], m: int, n: int, min_int: int = -1, max_int: int = -1) list[int][source]#

Method that adds to a list of positive integers the n subsequent and m prior integers of each integer in the list. Only adds the integers if they are not already in the list.

Parameters:
  • lst (list[int]) – List of integers.

  • m (int) – m prior integers of each element to add to list. If m = -1 all prior integers (until min) are added. If m = -1 and min_int = -1 all prior integers until the minimum integer in the list are added.

  • n (int) – n subsequent integers of each element to add to list. If n = -1 all subsequent integers (until max) are added. If n`= -1 and `max_int = -1 all subsequent integers until the maximum integer in the list are added.

  • min_int (int, default: -1 (no limit)) – Minimum integer to add.

  • max_int (int, default: -1 (no limit)) – Maximum integer to add.

Returns:

Extended list of integers.

Return type:

list[int]

Raises:
  • ValueError – If m or n are smaller than -1.

  • ValueError – If lst contains negative integers.

Examples

>>> add_context_integers([3, 4, 15], 1, 1, -1, -1)
[2, 3, 4, 5, 14, 15, 16]
>>> add_context_integers([3, 4, 15], 1, 2, -1, -1)
[2, 3, 4, 5, 6, 14, 15, 16, 17]
>>> add_context_integers([3, 4, 15], 3, 1, -1, -1)
[0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16]
>>> add_context_integers([3, 4, 15], -1, 1, -1, -1)
[3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>> add_context_integers([3, 4, 15], 1, -1, -1, -1)
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
>>> add_context_integers([3, 4, 15], -1, -1, 0, 18)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]