University of Arizona, Department of Computer Science

CSc 120: Shift a tuple

Expected Behavior

Write a function shift_tuple(tup, value) that takes as arguments a tuple tup of length n and a valuevalue. The function returns a new tuple consisting of the elements 1 through n-1 of tup and value.

Note: Do not use recursion to solve this problem.

Examples

  1. shift_tuple(('one', 'two', 'three'), 'four'))
    Return value: ('two', 'three', 'four')

  2. shift_tuple(('Half', 'a'), 'bee')
    Return value: ('a', 'bee')

  3. shift_tuple(('a', 'bee'), 'philosophically')
    Return value: ('bee', 'philosophically')

  4. shift_tuple(tuple(), 'one')
    Return value: ('one',)