# truncate_sequence¶

`sequencetools.``truncate_sequence`(sequence, sum_=None, weight=None)

Truncates sequence.

```>>> sequence = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
```

Example 1. Truncates sequence to weights ranging from 1 to 10:

```>>> for n in range(1, 11):
...     result = sequencetools.truncate_sequence(sequence, weight=n)
...     print(n, result)
...
1 [-1]
2 [-1, 1]
3 [-1, 2]
4 [-1, 2, -1]
5 [-1, 2, -2]
6 [-1, 2, -3]
7 [-1, 2, -3, 1]
8 [-1, 2, -3, 2]
9 [-1, 2, -3, 3]
10 [-1, 2, -3, 4]
```

Example 2. Truncates sequence to sums ranging from 1 to 10:

```>>> for n in range(1, 11):
...     result = sequencetools.truncate_sequence(sequence, sum_=n)
...     print(n, result)
...
1 [-1, 2]
2 [-1, 2, -3, 4]
3 [-1, 2, -3, 4, -5, 6]
4 [-1, 2, -3, 4, -5, 6, -7, 8]
5 [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
6 [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
7 [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
8 [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
9 [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
10 [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
```

Example 3. Truncates sequence to zero weight:

```>>> sequencetools.truncate_sequence(sequence, weight=0)
[]
```

Example 4. Truncates sequence to zero sum:

```>>> sequencetools.truncate_sequence(sequence, sum_=0)
[]
```

Ignores sum_ when weight and sum_ are both set.

Raises type error when sequence is not a list.

Raises value error on negative sum_.

Returns new object of sequence type.