les_iterables.sequences module
Summary
Functions:
Append an item to a sequence if it is not already present. |
|
Concatenate one of more sequences of compatible types. |
|
Extend a sequence with items which are not already present. |
|
Insert an item into a sequence if it is not already present. |
|
Remove n items from the end of a sequence. |
|
Prepend an item to a sequence if it is not already present. |
|
Replace the elements of s in a range with a new sequence. |
Reference
- les_iterables.sequences.pop_n(sequence, n, factory=None)[source]
Remove n items from the end of a sequence.
- Parameters:
sequence – The sequence from which to remove items.
n – The number of items to remove.
factory – The sequence return type. By default will be the same as the input type.
- Returns:
A sequence containing the removed items in the same order they were in the original sequence.
- Raises:
IndexError – If there are fewer than n items in the sequence.
- les_iterables.sequences.concat(sequence, *sequences)[source]
Concatenate one of more sequences of compatible types.
- Parameters:
sequence – A sequence.
*sequences – Additional sequences to concatenate with the first.
- Returns:
A concatenated sequences which has the same type as the first sequence.
- Raises:
TypeError – If the sequences are not of compatible types.
- les_iterables.sequences.replace_range(s, r: range | slice, t)[source]
Replace the elements of s in a range with a new sequence.
- Parameters:
s – The string in which a range is to be replaced.
r – A range or slice of indexes in s to be replaced.
t – The sequence with which to replace the elements of s in the range.
- Returns:
The sequence with the elements specified by a range of indexes replaced.
- les_iterables.sequences.append_unique(sequence, item) bool [source]
Append an item to a sequence if it is not already present.
- Parameters:
sequence – The sequence to which the item is to be appended.
item – The item to be appended.
- Returns:
True if the item was appended, False if it was already present.
- les_iterables.sequences.prepend_unique(sequence, item) bool [source]
Prepend an item to a sequence if it is not already present.
- Parameters:
sequence – The sequence to which the item is to be prepended.
item – The item to be prepended.
- Returns:
True if the item was prepended, False if it was already present.
- les_iterables.sequences.insert_unique(sequence, index, item) bool [source]
Insert an item into a sequence if it is not already present.
- Parameters:
sequence – The sequence into which the item is to be inserted.
index – The index at which the item is to be inserted.
item – The item to be inserted.
- Returns:
True if the item was inserted, False if it was already present.