List to Tuple Conversion

Write a Python program to convert a list to a tuple. Return the tuple.

Example 1:

Input: [5, 'hello', 8.3] 
Output: (5, 'hello', 8.3)

Example 2:

Input: [7, 'world', 3.14, 'd'] 
Output: (7, 'world', 3.14, 'd')

You can use the tuple() function to convert a list to a tuple.

def list_to_tuple(l):
    return tuple(l)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!