def getContour(semitones):
    """ Given a list of integers defining the size and direction of a series of musical intervals in semitones,
        this function encodes the contour of the melody with Parsons code for musical contour where u=up, d=down, r=repeat.
    """
    contour = ''
    for p in semitones:
        if p == 0:
            contour = contour + 'r'  # repeated
        elif p > 0:
            contour = contour + 'u'  # up
        elif p < 0:
            contour = contour + 'd'  # down
    return contour