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
WHAT DOES INFORMATION TECHNOLOGY DO??<br> Do they offer services or products
notsponge [240]
Yes

Explanation: Information technology, or IT, describes any technology that powers or enables the storage, processing and information flow within an organization. Anything involved with computers, software, networks, intranets, Web sites, servers, databases and telecommunications falls under the IT umbrella.
4 0
2 years ago
Why are there more producers then consumers?​
Ivanshal [37]

Answer:

because producer can make their own food

6 0
3 years ago
Read 2 more answers
Which cell address indicates the intersection of the first row and the first column in worksheet?
Rzqust [24]

Answer:

A. A1

Explanation:

Worksheet's Columns are named with Alphabets. i.e. A,B,C,D,E....

And Worksheet's rows are named with numbers. i.e. 1,2,3,4,5....

So the intersection of first row number as "1" and First Column name as "A" is A1 as worksheet displays column name first and then row number.

8 0
3 years ago
Read 2 more answers
Kali, a python programmer is using the turtle module to write the word hello, which code should she use to indicate the location
natta225 [31]

Answer:

D. # pick up the turtle and move it to (-100,200)

Explanation:

goto() option lets the user to move to a particular location.

so, goto(-100, 200) picks up the turtle and moves to the starting location will be used to indicate location to begin writing the word.

7 0
2 years ago
Read 2 more answers
What an underlined word or phrase represents? (HTML AND CSS), has to be 9 letters long. kinda urgent
xz_007 [3.2K]

Answer:

hyperlink

Explanation:

Hyperlinks render as underlined by default, so that's my guess.

7 0
3 years ago
Other questions:
  • Using caller id is part of which step in an effective time management plan
    10·1 answer
  • While doing research on the Internet, what kind of website should you avoid because the information may be biased?
    11·1 answer
  • What is the main feature of Ethernet over Power?
    9·1 answer
  • A lack of financial literacy can cause you to lose your
    10·1 answer
  • For each 8-bit data frame the layer uses a generator polynomial G(x) = x4+x2+ x+1 to add redundant bits. What is the sequence of
    11·1 answer
  • Who was the creator of the game Fnaf?
    11·2 answers
  • How can you tell the value of a purchase?
    7·1 answer
  • Plz help Complete the sentence.
    11·2 answers
  • Five types of conflict in the school​
    9·2 answers
  • 8. The cell reference for a range of cells that starts in cell A1 and goes over to column G and down to row 10 is, a. A1-G10 b.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!