def slice(seq, indices):
    """Performs a Perl-style slice, substituting None for out-of-range
    indices rather than raising an exception.
    """
    sliced = []
    for index in indices:
        try:
            sliced.append(seq[int(index)])
        except IndexError:
            sliced.append(None)
    return sliced
