Word utilities (DEPRECATED)

Note

This module will be deleted in a future version of Sage. Most of the commands here have been already deleted; only the commands needed for unpickling word objects saved with older versions of Sage (pre 4.1) have been kept (for now).

sage.combinat.words.utils.clamp(x, min, max)

This function is deprecated and will be deleted in a future version of Sage.

Clamp a value between a maximum and a minimum.

EXAMPLES:

sage: from sage.combinat.words.utils import clamp
sage: clamp(0, -1, 1)
0
sage: clamp(-2, 0, 4)
0
sage: clamp(10, 0, 4)
4
sage.combinat.words.utils.copy_it(it)

This function is deprecated and will be deleted in a future version of Sage.

Copy an iterator using its builtin __copy__ method if available, otherwise use itertools.tee(). Define __copy__ for your iterators. (See PEP 323)

TESTS:

sage: from sage.combinat.words.utils import copy_it
sage: it = iter([1, 2, 3, 4, 5])
sage: it, it2 = copy_it(it)
sage: list(it)
[1, 2, 3, 4, 5]
sage: it2.next()
1
sage: it2, it3 = copy_it(it2)
sage: list(it2)
[2, 3, 4, 5]
sage: it3.next()
2
sage.combinat.words.utils.haslen(obj)

This function is deprecated and will be deleted in a future version of Sage.

Returns true if obj has a properly defined length

EXAMPLES:

sage: from sage.combinat.words.utils import haslen
sage: haslen([1, 2, 3])
True
sage: haslen(33)
False

TESTS:

sage: class test(object):
...     def __len__(self):
...         return -1
...
sage: haslen(test())
False
sage.combinat.words.utils.id_f(x)

This function is deprecated and will be deleted in a future version of Sage.

Dummy identity function for when a function is required but none is desired.

Note

This function is needed required so that words saved in earlier versions of Sage can be loaded; and will be deleted in a future version of Sage.

TESTS:

sage: from sage.combinat.words.utils import id_f
sage: l = [1, 2, 3]
sage: l is id_f(l)
True
sage.combinat.words.utils.is_iterable(obj)

This function is deprecated and will be deleted in a future version of Sage.

Returns true if the obj is iterable.

EXAMPLES:

sage: from sage.combinat.words.utils import is_iterable
sage: is_iterable('123')
True
sage: is_iterable([1, 2, 3])
True
sage: is_iterable(xrange(1, 4))
True
sage: is_iterable(33)
False
sage.combinat.words.utils.isint(obj)

This function is deprecated and will be deleted in a future version of Sage.

Returns True if obj is an integer or a custom object representing an integer and False otherwise.

EXAMPLES:

sage: from sage.combinat.words.utils import isint
sage: isint(1)
True
sage: isint("2")
False
sage: isint(1.0)
False
sage.combinat.words.utils.len_it(it)

This function is deprecated and will be deleted in a future version of Sage.

Returns the number of elements in it.

This function will modify the iterator, so if you want to access the elements later, make a copy of the iterator and pass it to this function.

EXAMPLES:

sage: from sage.combinat.words.utils import len_it
sage: len_it(iter([1, 2, 3]))
3
sage.combinat.words.utils.peek_it(it)

This function is deprecated and will be deleted in a future version of Sage.

Returns the first element of an iterator and returns an iterator at the same position as the original iterator

EXAMPLES:

sage: from sage.combinat.words.utils import peek_it
sage: it = iter([1, 2, 3])
sage: it, n = peek_it(it); n
1
sage: it.next()
1
sage.combinat.words.utils.reverse_map(d)

This function is deprecated and will be deleted in a future version of Sage.

Return a new dict with swapped keys and values

EXAMPLES:

sage: from sage.combinat.words.utils import reverse_map
sage: reverse_map({'a': 1, 'b': 2}) == {1: 'a', 2: 'b'}
True
sage.combinat.words.utils.slice_indices(s, l)

This function is deprecated and will be deleted in a future version of Sage.

Implement slice.indices without bugs.

TESTS:

sage: from sage.combinat.words.utils import slice_indices
sage: slice_indices(slice(None), 8)
(0, 8, 1)
sage: slice_indices(slice(1), 8)
(0, 1, 1)
sage: slice_indices(slice(10), 8)
(0, 8, 1)
sage: slice_indices(slice(-4), 8)
(0, 4, 1)
sage: slice_indices(slice(-10), 8)
(0, 0, 1)
sage: slice_indices(slice(1, None), 8)
(1, 8, 1)
sage: slice_indices(slice(10, None), 8)
(8, 8, 1)
sage: slice_indices(slice(-4, None), 8)
(4, 8, 1)
sage: slice_indices(slice(-10, None), 8)
(0, 8, 1)
sage: slice_indices(slice(None, None, 2), 8)
(0, 8, 2)
sage: slice_indices(slice(None, None, -2), 8)
(7, -1, -2)
sage.combinat.words.utils.slice_it(it, l, key)

This function is deprecated and will be deleted in a future version of Sage.

Slice an iterator, supporting negative step sizes by expliciting the elements if needed.

NOTE: The iterator returned depends on it. You must pass in a copy of your iterator if you intend to keep using the original iterator.

TESTS:

sage: from sage.combinat.words.utils import slice_it
sage: list(slice_it(iter(range(5)), 5, slice(None)))
[0, 1, 2, 3, 4]
sage: list(slice_it(iter(range(5)), 5, slice(3)))
[0, 1, 2]
sage: list(slice_it(iter(range(5)), 5, slice(-1)))
[0, 1, 2, 3]
sage: list(slice_it(iter(range(5)), 5, slice(2, 4)))
[2, 3]
sage: list(slice_it(iter(range(5)), 5, slice(3, 1, -1)))
[3, 2]
sage.combinat.words.utils.slice_ok(part)

This function is deprecated and will be deleted in a future version of Sage.

Returns true if part is a slice and doesn’t have funny values.

EXAMPLES:

sage: from sage.combinat.words.utils import slice_ok
sage: slice_ok(slice(None))
True
sage: slice_ok(slice(2))
True
sage: slice_ok(slice(1, 2, 3))
True
sage: slice_ok(slice(None, 2, 3))
True
sage: slice_ok(slice(1, None, 3))
True
sage: slice_ok(slice(1, 2, None))
True
sage: slice_ok(slice("a"))
False
sage: slice_ok(slice("a", 1))
False
sage: slice_ok(slice(1, 2, "a"))
False
sage: slice_ok(1)
False
sage.combinat.words.utils.sliceable(obj)

This function is deprecated and will be deleted in a future version of Sage.

Returns true if obj is completely sliceable, including negative step sizes

EXAMPLES:

sage: from sage.combinat.words.utils import sliceable
sage: sliceable([1, 2, 3])
True
sage: sliceable(33)
False

TESTS:

sage: class test(object):
...     def __getitem__(self, key):
...         return islice(iter([1]), *key)
...
sage: sliceable(test())
False

Previous topic

Word paths

Next topic

Word contents (DEPRECATED)

This Page