Creating a Shallow Copy of a Set

Tags: copy, Set

Write a Python program to create a shallow copy of a set. The function should return the copy of the set.

Example 1:

Input: {1, 2, 3, 4, 5} 
Output: {1, 2, 3, 4, 5}

Example 2:

Input: {"apple", "banana", "cherry"} 
Output: {"apple", "banana", "cherry"}

Use the copy() method in Python to create a copy of a set.

def create_copy(set1):
    return set1.copy()

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!