A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Checks if one set is a subset or superset of another set. If found, delete all elements from that set using python programming
Q:

Checks if one set is a subset or superset of another set. If found, delete all elements from that set using python programming

0

Checks if one set is a subset or superset of another set. If found, delete all elements from that set

Given:

first_set = {27, 43, 34}
second_set = {34, 93, 22, 27, 43, 53, 48}

Expected Output:

First set is subset of second set - True
Second set is subset of First set -  False

First set is Super set of second set -  False
Second set is Super set of First set -  True

First Set  set()
Second Set  {67, 73, 43, 48, 83, 57, 29}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use the below methods of a set class

  • issubset()
  • issuperset()
  • clear()

Solution:

first_set = {57, 83, 29}
second_set = {57, 83, 29, 67, 73, 43, 48}

print("First Set ", first_set)
print("Second Set ", second_set)

print("First set is subset of second set -", first_set.issubset(second_set))
print("Second set is subset of First set - ", second_set.issubset(first_set))

print("First set is Super set of second set - ", first_set.issuperset(second_set))
print("Second set is Super set of First set - ", second_set.issuperset(first_set))

if first_set.issubset(second_set):
    first_set.clear()

if second_set.issubset(first_set):
    second_set.clear()

print("First Set ", first_set)
print("Second Set ", second_set)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now