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]
2 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]2 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
In the United States there are more women than men, but women are referred to as a minority group? Why are they considered a min
ziro4ka [17]
Cause they make up half the population of the united states of america
7 0
2 years ago
Read 2 more answers
What is a "telescreen"? How is it different from the televisions we know? Is it possible to make a television that could see and
mars1129 [50]

Answer:

  1. Telescreens are devices that operate as televisions, security cameras, and microphones.
  2. A television is an electronic communication medium that allows the transmission of real-time visual images, and often sound while a telescreen is a television and security camera-like device used to keep things or people under constant surveillance, thus eliminating the chance of secret conspiracies.
  3. It could be employed in secretly investigating criminals and terrorists.
  4. It could also play a major role in politics by investigating suspicious government officials and those that plan Ill towards a nation.
  5. It would definitely be a great idea to install one of such.

Explanation:

8 0
2 years ago
What is the output?
Scilla [17]

Answer:

The output of the code,

phrase = "hello mom"

phrase.upper()

Would be nothing since you didnt print out anything. How ever, the output of,

phrase = "hello mom"

print(phrase.upper())

Would be, "HELLO MOM". You can get the same output by writing this,

phrase = "hello mom"

phrase = phrase.upper()

print(phrase)

3 0
2 years ago
Read 2 more answers
Question 4 (1 point)
Leno4ka [110]

Answer:

I need the know what "the following" are! Then I can answer!

Explanation:

6 0
3 years ago
What will you see on the next line?<br> &gt;&gt;&gt; int(13.6)
atroni [7]

Answer:

13

Explanation:

4 0
3 years ago
Other questions:
  • Operating system software allows you to use your fingers, a mouse or other pointing device to select screen controls, such as bu
    5·2 answers
  • Similarities between human and computer​
    12·1 answer
  • What type of maintenance can prevent the computer from breaking?
    11·2 answers
  • ____ technology essentially takes the data to be transmitted and rather than transmitting it in a fixed bandwidth spreads it ove
    15·1 answer
  • The instant pivot button is displayed in the statistics and visualization tabs when a _______ search is run.
    15·1 answer
  • You cannot be everywhere at once, but your freedom allows you to
    5·1 answer
  • When you check your hard drive to see how much space is available, you are checking your
    15·1 answer
  • You can set the margin using the rular also true or false​
    13·1 answer
  • Which of the following statements is correct? User data cannot be combined and shared among authorized users. In a nondatabase,
    6·1 answer
  • RDBMSs enforce integrity rules automatically. <br> a. True<br> b. False
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!