Slice a Tuple

Tags: Slicing, tuple

Write a Python program to slice a tuple.

Example 1:

Input: (1, 2, 3, 4, 5), 2, 4 
Output: (3, 4)

Example 2:

Input: ('a', 'b', 'c', 'd', 'e'), 1, 3 
Output: ('b', 'c')

Use Python’s slice notation to perform this task.

def slice_tuple(t, start, end):
    return t[start:end]

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!