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 →Check Strict Superset Python
You are given a set A and n other sets. Your job is to find whether set A is a strict superset of each of the N sets. Print True, if A is a strict superset of each of the N sets. Otherwise, print False. A strict superset has at least one element that does not exist in its subset. Example Set ([1,3,4]) is a strict superset of set ([1,3]). Set ([1,3,4]) is not a strict superset of set ([1,3,4]). Set ([1,3,4]) is not a strict superset of set ([1,3,5]). Input Format The first li
View Solution →itertools.product() python
itertools.product() This tool computes the cartesian product of input iterables. It is equivalent to nested for-loops. For example, product(A, B) returns the same as ((x,y) for x in A for y in B). Sample Code >>> from itertools import product >>> >>> print list(product([1,2,3],repeat = 2)) [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)] >>> >>> print list(product([1,2,3],[3,4])) [(1, 3), (1, 4), (2, 3), (2, 4), (3, 3), (3, 4)] >>> >>> A = [[1,2,3],[3,4
View Solution →