Find Tuple Index

Tags: index, tuple

Write a Python program to find the index of a particular item in a tuple.

Example 1:

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

Example 2:

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

Use the index() method for this task.

def find_index(t, item):
    return t.index(item)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!