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
Louis is a civil engineer and wants to use a line on a floor plan that is indicative of the position from which a section is tak
frutty [35]

Answer:

A

Explanation:

horizontal line

8 0
2 years ago
Read 2 more answers
Write a function solution that given an array a of n integers (between -100 and 100), returns the sign (-1,0,1) of product of al
JulijaS [17]

left[0]=a[0];

for(int i=1;i<=n-1;i++)

   left[i]=(left[i-1]*a[i])%M;

right[n-1]=a[n-1];

for(int i=n-2;i>=0;i--)

   right[i]=(right[i-1]*a[i])%M;

for query q

   if(q==0)

       return right[1]%M;

   if(q==n-1)

       return left[n-2]%M;

   return (left[q-1]*right[q+1])%M;

4 0
2 years ago
The 3 parts of the CPU are
katrin2010 [14]

Central Processing Unit

Arithmitic Logic Unit

Control Unit


3 0
3 years ago
Read 2 more answers
According to the Center for 21st Century Skills, critical thinking ability includes all of the following skills, EXCEPT ______.
Readme [11.4K]

Answer:

communicate clearly

Explanation:

4 0
3 years ago
A physical cpu core without hyper-threading enabled can process two instructions at the same time.
diamong [38]

A physical CPU core without hyper-threading enabled can process two instructions at the same time is a false statement.

<h3>Can a CPU do multiple things at once?</h3>

Computers are those that do only one task (or process) at a single time. But a computer can alter tasks very fast and can do a lot of work.

The Central processing unit is known to be the brain of the computer system and without it, the computer cannot function or be turn on.

Hence, A physical CPU core without hyper-threading enabled can process two instructions at the same time is a false statement.

Learn more about CPU from

brainly.com/question/474553

#SPJ1

3 0
2 years ago
Other questions:
  • What aspect do you need to keep in mind when you add images in a word document?
    11·2 answers
  • What was one of the main purposes of the first computer systems?
    11·1 answer
  • Barr the Bear has started a business to sell fish to Poe and his fellow penguins. The penguin customers submit many fish orders,
    12·1 answer
  • Variables used for output are associated with what controls on a form?​
    5·1 answer
  • Write a function named get_my_age that returns your age as an int (this is YOUR age, so if you were 21 you would return the numb
    11·1 answer
  • Priscilla is providing the junior analysts in her firm with some real-world illustrations to explain some of the recommendations
    12·1 answer
  • Introduction to computing systems: from bits and gates to c and beyond
    7·1 answer
  • Need the answer ASAP!!!
    14·1 answer
  • Please help me I need a help
    13·1 answer
  • What are the methods of gilding<br><br>nonsense will be immediately reported. ​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!