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
Which of the following is not a characteristic of a healthy relation?
dlinn [17]
Where is the problem at?
5 0
4 years ago
What is that tool that makes liquid metal? It is used for wires, Ik I might sound dumb but I'm rlly curious​
Alex_Xolod [135]

Answer:

A blow torch?

Explanation:

4 0
3 years ago
In a non-price rationing system, consumers receive goods and services first-come, first served. Give me an example of a time whe
Anna35 [415]

When someone may be giving away something for free.

7 0
3 years ago
Which part of a computer s ip address configuration indicates the portion of the address that specifies the network address?
vivado [14]
The NETWORK mask is and'ed with the IP address to get the network number.

Example:

192.168.1.1 & 255.255.255.0 = 192.168.1.0/24

It's worth the effort to do this in binary, it makes much more sense.
4 0
3 years ago
I keep getting this error: postfix.cpp: In function ‘double RPN_evaluation(std::string)’: postfix.cpp:42:26: error: cannot conve
Svetradugi [14.3K]

Answer:

expr.at(g) returns a string, not a char. They are not the same thing and that is what the compiler is complaining about.

3 0
4 years ago
Other questions:
  • Suppose a retailer who has no technology expertise wishes to set up an online presence for his business. He ________. a. ​can us
    6·1 answer
  • Write a Java program that generates a random number between 0 and 50. Then, the program prompts for guesses until the user is co
    14·1 answer
  • A wide variety of “apps” are available to customize devices. Which category of app does word processing software fall into?
    14·2 answers
  • Can somebody please halp meeee?? I'm doing Web design.
    12·2 answers
  • __ provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debu
    15·1 answer
  • What is the difference between a heap (a minheap) and a binary search tree?
    12·1 answer
  • 1. Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the result assigned to a var
    8·1 answer
  • Why does a CPU need Thermal Grease?
    14·1 answer
  • A sequence of direct connections
    10·1 answer
  • how can you turn on a light switch and it not work, without turning off the power to the whole house?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!