<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def addJunctionPos(shape, fromPos, toPos):
 """Extends shape with the given positions in case they differ from the existing endpoints. assumes that shape and positions have the same dimensionality"""

    result = list(shape)
    if fromPos != shape[0]:
        result = [fromPos] + result
    if toPos != shape[-1]:
        result.append(toPos)
    return result