title-img


Set.difference() Operation

.difference() The tool .difference() returns a set with all the elements from the set that are not in an iterable. Sometimes the - operator is used in place of the .difference() tool, but it only operates on the set of elements in set. Set is immutable to the .difference() operation (or the - operation). >>> s = set("Hacker") >>> print s.difference("Rank") set(['c', 'r', 'e', 'H']) >>> print s.difference(set(['R', 'a', 'n', 'k'])) set(['c', 'r', 'e', 'H']) >>> print s.difference([

View Solution →

Set.symmetric_difference() Operation python

.symmetric_difference() The .symmetric_difference() operator returns a set with all the elements that are in the set and the iterable but not both. Sometimes, a ^ operator is used in place of the .symmetric_difference() tool, but it only operates on the set of elements in set. The set is immutable to the .symmetric_difference() operation (or ^ operation). >>> s = set("Hacker") >>> print s.symmetric_difference("Rank") set(['c', 'e', 'H', 'n', 'R', 'r']) >>> print s.symmetric_difference

View Solution →

Set Mutations Python

We have seen the applications of union, intersection, difference and symmetric difference operations, but these operations do not make any changes or mutations to the set. We can use the following operations to create mutations to a set: .update() or |= Update the set by adding elements from an iterable/another set. >>> H = set("Hacker") >>> R = set("Rank") >>> H.update(R) >>> print H set(['a', 'c', 'e', 'H', 'k', 'n', 'r', 'R']) .intersection_update() or &= Update the set by

View Solution →

The Captain's Room Python

Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms. One fine day, a finite number of tourists come to stay at the hotel. The tourists consist of: → A Captain. → An unknown group of families consisting of K members per group where K ≠ 1. The Captain was given a separate room, and the rest were given one room per group. Mr. Anant has an unordered list of randomly arranged room entries. The list consists of the room numbers for all of the

View Solution →

Check Subset Python

You are given two sets, A and B. Your job is to find whether set A is a subset of set B. If set A is subset of set B, print True. If set A is not a subset of set B, print False. Input Format The first line will contain the number of test cases, T. The first line of each test case contains the number of elements in set A. The second line of each test case contains the space separated elements of set A. The third line of each test case contains the number of elements in set B. The

View Solution →