{"id":25071,"date":"2021-11-10T09:38:02","date_gmt":"2021-11-10T04:08:02","guid":{"rendered":"https:\/\/python-programs.com\/?p=25071"},"modified":"2021-11-10T09:38:02","modified_gmt":"2021-11-10T04:08:02","slug":"python-set-issuperset-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-set-issuperset-method-with-examples\/","title":{"rendered":"Python Set issuperset() Method with Examples"},"content":{"rendered":"
Python set() Function with Examples<\/span><\/a><\/p>\n Set issuperset() Method in Python:<\/strong><\/p>\n If all items in the specified set exist in the original set, the issuperset() method returns true; otherwise, it returns False.<\/p>\n For Example,<\/p>\n Let p = {1, 2, 3}<\/p>\n q= {1, 2, 3, 4, 5, 6}<\/p>\n Here all the elements of set ‘p ‘ are in the set ‘q’ . Hence set q<\/strong> is the superset<\/strong> of set p<\/strong>.<\/p>\n And set p<\/strong> is the subset of set q.<\/strong><\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n set:<\/strong>\u00a0This is\u00a0 Required. It is the set to look for items that are similar.<\/p>\n Return Value:<\/strong><\/p>\n issuperset() gives<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" Prerequisite: Python set() Function with Examples Set issuperset() Method in Python: If all items in the specified set exist in the original set, the issuperset() method returns true; otherwise, it returns False. For Example, Let p = {1, 2, 3} q= {1, 2, 3, 4, 5, 6} Here all the elements of set ‘p ‘ …<\/p>\nset.issuperset(set)<\/pre>\n
\n
Given first set = {20, 30, 100}\r\nGiven second set = {100, 20, 80, 70, 30}<\/pre>\n
Check if the given second set is superset of the first set: True<\/pre>\n
Given first set = {20, 30, 100, 12, 15, 16}\r\nGiven second set = {12, 15, 16}<\/pre>\n
Check if the given second set is superset of the first set: False<\/pre>\n
Here the first set is the superset of the second set. \r\nBut Not the second set is a superset of the first. Hence it returns False.<\/pre>\n
Set issuperset() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the first set as static input and store it in a variable.\r\nfst_set = {20, 30, 100}\r\n# Give the second set as static input and store it in another variable.\r\nscnd_set = {100, 20, 80, 70, 30}\r\n# Apply the issuperset() method to the given first and second sets to check if the\r\n# given second set is the superset of the first set or not.\r\n# Store it in another variable.\r\nrslt = scnd_set.issuperset(fst_set)\r\n# Print the above result.\r\nprint(\"Check if the given second set is superset of the first set:\", rslt)\r\n<\/pre>\n
Check if the given second set is superset of the first set: True<\/pre>\n
Similarly, check for the other example<\/h5>\n
fst_set = {20, 30, 100, 12, 15, 16}\r\nscnd_set = {12, 15, 16}\r\nrslt = scnd_set.issuperset(fst_set)\r\nprint(\"Check if the given second set is superset of the first set:\", rslt)\r\n<\/pre>\n
Check if the given second set is superset of the first set: False<\/pre>\n
Here the first set is the superset of the second set. \r\nBut Not the second set is a superset of the first. Hence it returns False.<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the first set as user input using set(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\nfst_set = set(map(int, input(\r\n 'Enter some random Set Elements separated by spaces = ').split()))\r\n# Give the second set as user input using set(),map(),input(),and split() functions.\r\n# Store it in another variable.\r\nscnd_set = set(map(int, input(\r\n 'Enter some random Set Elements separated by spaces = ').split()))\r\n\r\n# Apply the issuperset() method to the given first and second sets to check if the\r\n# given second set is the superset of the first set or not.\r\n# Store it in another variable.\r\nrslt = scnd_set.issuperset(fst_set)\r\n# Print the above result.\r\nprint(\"Check if the given second set is superset of the first set:\", rslt)\r\n<\/pre>\n
Enter some random Set Elements separated by spaces = 10 12 14 16\r\nEnter some random Set Elements separated by spaces = 12 13\r\nCheck if the given second set is superset of the first set: False<\/pre>\n