def permute(seq, p):
    """Permute the elements of a sequence according to a permutation.

    :param seq: a sequence to be permuted
    :param p: a permutation (sequence of integers between ``0`` and
              ``len(seq) - 1``)
    :returns: ``tuple(seq[i] for i in p)``
    :rtype: tuple
    """
    return tuple(seq[i] for i in p)