def turn(orientation, direction):
    """Given an orientation on the compass
    and a direction ("L" or "R"), return a
    a new orientation after turning 90 deg
    in the specified direction."""
    compass = ['N', 'E', 'S', 'W']
    if orientation not in compass:
        raise ValueError('orientation must be N, E, S, or W')
    if direction not in ['R', 'L']:
        raise ValueError('direction must be R or L')
    i = (compass.index(orientation) + (1 if direction == 'R' else -1)) % len(compass)
    return compass[i]