• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Python issuperset() Function – Check if Set is Superset of Another Set

Python issuperset() Function – Check if Set is Superset of Another Set

July 15, 2022 Leave a Comment

The Python issuperset() function allows you to check if a set is a superset of another set.

a = {1, 2, 3}
b = {1, 2, 3, 4, 5, 6}

print(b.issuperset(a))

#Output:
True

When working with different collections of data, the ability to easily determine properties of these objects can be useful.

One such property is if a set is a superset of another set.

A set X is a superset of another set Y if all of the elements of the set Y are in the set X.

In Python, you can use the issuperset() function to check if a set is a superset of another set. issuperset() returns a boolean value.

Below is a simple example showing you how to check if a set is a superset of another set using the issuperset() function in Python.

a = {1, 2, 3}
b = {1, 2, 3, 4, 5, 6}

print(b.issuperset(a))

#Output:
True

Using > and ≥ Operators to Check if Set is Superset in Python

In addition to the issuperset() function, you can also use the > and ≥ operators to check if a set is a superset of another set.

The > operator checks if the superset is a proper superset, and ≥ checks if the set is a superset with the chance of it being equal.

Below are some examples showing how to use the > and ≥ operators to check if a set is a superset of another set in Python.

a = {1, 2, 3}
b = {1, 2, 3, 4, 5, 6}

print(b > a)
print(b > b)
print(b >= a)
print(b >= b)

#Output:
True
False
True
True

Using Python issubset() Function to Check if Set is Superset of Another Set

If you want to go the other way and check if a set is a subset of another set, or that all of the elements of the set are also in the other set, then you can use the issubset() function.

Just like issuperset(), issubset() returns a boolean value.

Below is a simple example showing you how to check if a set is a superset of another set using the issubset() function in Python.

a = {1, 2, 3}
b = {1, 2, 3, 4, 5, 6}

print(a.issubset(b))

#Output:
True

Hopefully this article has been useful for you to learn how to use the issuperset() function in Python.

Other Articles You'll Also Like:

  • 1.  Get Week Number from Date in Python
  • 2.  Using GroupBy() to Group Pandas DataFrame by Multiple Columns
  • 3.  pandas Drop Columns – Delete Columns from a DataFrame
  • 4.  How Clear a Set and Remove All Items in Python
  • 5.  Writing Multiple Lines Lambda Expression in Python
  • 6.  Why Dictionaries Can’t Have Duplicate Keys in Python
  • 7.  How to Group By Columns and Find Maximum in pandas DataFrame
  • 8.  Python Add Months to Datetime Variable Using relativedelta() Function
  • 9.  pandas startswith() – Check if String Starts With Certain Characters
  • 10.  pandas floor – Find the Floor of a Column Using Numpy floor

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy