1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergejj [24]
3 years ago
6

Write a Python function check_subset() that takes in two Python lists, representing sets of integers, A and B. Your function sho

uld return a single Boolean (True or False) for whether or not either set is a subset of the other. A and B are sets, and not necessarily non-empty.
Computers and Technology
1 answer:
wlad13 [49]3 years ago
6 0

Answer:

  1. def check_subset(l1, l2):
  2.    status = False
  3.    count = 0
  4.    if(len(l1) > len(l2)):
  5.        for x in l2:
  6.            for y in l1:
  7.                if x == y:
  8.                    count += 1
  9.        if(count == len(l2)):
  10.            return True  
  11.        else:
  12.            return False
  13.    else:
  14.        for x in l1:
  15.            for y in l2:
  16.                if x==y:
  17.                    count += 1
  18.        if(count == len(l1)):
  19.            return True  
  20.        else:
  21.            return False
  22. print(check_subset([1,4,6], [1,2,3,4,5,6]))
  23. print(check_subset([2,5,7,9,8], [7,8]))
  24. print(check_subset([1, 5, 7], [1,4,6,78,12]))

Explanation:

The key idea of this solution is to create a count variable to track the number of the elements in a shorter list whose value can be found in another longer list.

Firstly, we need to check which list is shorter (Line 4). If the list 2 is shorter, we need to traverse through the list 2 in an outer loop (Line 5) and then create another inner loop to traverse through the longer list 1 (Line 6).  If the current x value from list 2 is matched any value in list 1, increment the count variable by 1. After finishing the outer loop and inner loop, we shall be able to get the total count of elements in list 2 which can also be found in list 1. If the count is equal to the length of list 2, it means all elements in the list 2 are found in the list 1 and therefore it is a subset of list 1 and return true (Line 10-11) otherwise return false.

The similar process is applied to the situation where the list 1 is shorter than list 2 (Line 15-24)

If we test our function using three pairs of input lists (Line 26-28), we shall get the output as follows:

True

True

False

You might be interested in
How to set a prperty to all intems in array c#
Katena32 [7]
Try looking at this site, <span>www.c-sharpcorner.com/article/working-with-arrays-in-C-Sharp/</span>
6 0
3 years ago
Type the correct answer in the box. Spell all words correctly.
Ugo [173]

Answer:

Business format franchise or Business Brokers

Explanation:

8 0
3 years ago
Which of the following are benefits of designing a scalable system? Choose 3 options.
zhenek [66]

Which of the following are benefits of designing a scalable system? Choose 3 options.

  • ability to maintain a high level of service for customers ✔

system will never need to grow again

  • Ability to respond to user volume issues more quickly ✔
  • guaranteed system access for all users ✔

users may never know that a site has experienced tremendous growth

4 0
3 years ago
When a web page author includes meta keywords, like sex, that have little to do with the information on the page, the author is
OLga [1]
This practice is known as "ClickBait".
8 0
3 years ago
V.kofiryfh givnyovb (to slove you must go back 3 letters)
Elena L [17]
Im goin to be honest with you i dont understand this question at all can you xplain it alittle more plz cuz if i go back three letters it is o
7 0
3 years ago
Other questions:
  • Imagine the world in 2030 and write a letter to your future self. Be sure to mention things that you think your future self woul
    8·1 answer
  • What is an advantage of using a meta-search engine?
    14·1 answer
  • Which task is performed by the artificial intelligence programmer?
    7·1 answer
  • An operating environment for a computer is ____, free of potential contaminants, and with the temperature and humidity range spe
    9·1 answer
  • What should you do before using a website to store student information ? A. Read and understand the website’s privacy contract
    11·2 answers
  • When a new word processing software program is released, companies that might use it must consider not only the cost of buying i
    13·1 answer
  • Suppose you are given a sequence that is described by a formula, starting at index n=0. If you need to change the starting index
    6·1 answer
  • How can having more than one goal cause truble in the work place
    6·1 answer
  • 9.6 Code Practice, this is in Python, I need its quick!
    13·1 answer
  • Plz help me I need help​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!