def set_prev_next(sequence):
    """Set "prev" and "next" attributes of each element of a sequence"""
    sequence = list(sequence)
    for prev, now, next in zip([None] + sequence, sequence, sequence[1:] +
        [None]):
        now.prev = prev
        now.next = next
