Question 1: How to find the unique elements in a list without using a for loop?
# 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 )
Question 3: How to merge two lists and remove duplicates without using a for loop?
# 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 )
Question 4: Is there a way to check if two lists are completely identical without using a for loop?
# Ans:
list1 = [1 , 2 , 3 , 4 , 5 ]
list2 = [1 , 2 , 3 , 4 , 5 ]
are_lists_identical = set (list1 ) == set (list2 )
print (are_lists_identical )
Question 5: How can you find the difference between two lists without using a for loop?
# Ans:
list1 = [1 , 2 , 3 , 4 , 5 ]
list2 = [3 , 4 , 5 , 6 , 7 ]
difference_elements = list (set (list1 ) ^ set (list2 ))
print (difference_elements )