Write a program that takes numbers in a list and returns a new list with distinct elements from the first list.
Code:
def remove_duplicates(input_list):
# Convert the list to a set to remove duplicates
distinct_elements_set = set(input_list)
# Convert the set back to a list
distinct_elements_list = list(distinct_elements_set)
return distinct_elements_list
# Example usage
if __name__ == "__main__":
# Input list with duplicate elements
input_list = [1, 2, 3, 3, 4, 4, 5]
# Call the function to remove duplicates
distinct_elements = remove_duplicates(input_list)
# Print the list with distinct elements
print("List with distinct elements:", distinct_elements)
0 Comments