-
Notifications
You must be signed in to change notification settings - Fork 2
QNA related to set
Praveen Kumar Anwla edited this page Jan 24, 2024
·
1 revision
# Ans:
my_list = [1, 2, 2, 3, 4, 4, 5, 6]
unique_elements = list(set(my_list))
print(unique_elements)
Question 2: Can you retrieve the elements that are only present in the first list and not in the second list without using a for loop?
# Ans:
list1 = [1, 2, 3, 4, 5]
list2 = [3, 4, 5, 6, 7]
unique_elements_in_list1 = list(set(list1) - set(list2))
print(unique_elements_in_list1)
# Ans:
list1 = [1, 2, 3, 4, 5]
list2 = [3, 4, 5, 6, 7]
merged_list_without_duplicates = list(set(list1 + list2))
print(merged_list_without_duplicates)
# Ans:
list1 = [1, 2, 3, 4, 5]
list2 = [1, 2, 3, 4, 5]
are_lists_identical = set(list1) == set(list2)
print(are_lists_identical)
# Ans:
list1 = [1, 2, 3, 4, 5]
list2 = [3, 4, 5, 6, 7]
difference_elements = list(set(list1) ^ set(list2))
print(difference_elements)