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
sesenic [268]
3 years ago
7

Write a function list_intersection that takes two lists as parameters. Return a list that gives the intersection of the two list

s- ie, a list of elements that are common to both lists. Run the following test cases and make sure your results are the same (the ordering of your outputs does not matter - [3,2] is the same as [2,3]):
Computers and Technology
2 answers:
Contact [7]3 years ago
6 0

Answer:

  1. def list_intersection(l1, l2):
  2.    inter_list = []
  3.    for x in l1:
  4.        for y in l2:
  5.            if(y == x):
  6.                if(x not in inter_list):
  7.                    inter_list.append(x)
  8.    return inter_list  
  9. list1 = [3, 5, 5, 7, 7, 10]
  10. list2 = [4, 6, 7, 7, 8, 8, 10]
  11. print(list_intersection(list1, list2))

Explanation:

The solution code is written in Python.

Firstly, create a function list_intersection that takes two input lists, l1 and l2 (Line 1). Next, create a new list, inter_list, to hold the intersect numbers from the two input lists (Line 2).

Create a two-layer for loop to traverse through every number in l1 and compare it with every number in l2 (Line 4 - 5). If any one of the numbers from l2 is equal to the current number from L1, add this common number to inter_list (Line 8). This is important to check the current common number is not in the inter_list (Line 7) to avoid number duplication.

We can test the function using the two sample lists (Line 12 -13) and print the result (Line 14). We shall get the output [7, 10].

Nataliya [291]3 years ago
4 0

Answer:

def list_intersection(list1, list2):

   intersected_list = [number for number in list1 if number in list2]

   return intersected_list

 

list1 = [11, 5, 676, 0, 42, 32]

list2 = [0, 89, 211, 11]

print(list_intersection(list1, list2))

Explanation:

- Inside the function, create a new list called <em>intersected_list </em>to check if any number in <em>list1</em> is also in the <em>list2</em>. If a match is found put the number in the <em>intersected_list. </em>* Take a look how Python enables us to do this with just one line of code

- Then create two lists to compare

- Call the function and print the result

You might be interested in
A form letter can be customized by using different fields in a __________.
alexgriva [62]
I think the answer to this is  C.email
4 0
3 years ago
Read 2 more answers
You should reach across something to lift a load is this true or false
Grace [21]

Answer:

False. Never reach across a load when you're trying to lift it.

3 0
3 years ago
Rayna wants to create an organizational chart in her document. Which of the following commands should she click in the Illustrat
WITCHER [35]
CHART
that’s my answer
7 0
3 years ago
Draw a full binary tree of height 2. How many nodes does it have?
Paraphin [41]

Answer:

The number of nodes in a full binary tree of height 2 = 7

Explanation:

At each level k, of the full binary tree there are usually 2^{k} \\ nodes.

So the full binary tree of height 2 has nodes= 2^{0} \\ + 2^{1} \\ + 2^{2} \\.

which is 7.

6 0
4 years ago
Which step in the penetration testing life cycle is accomplished using rootkits or trojan horse programs? maintain access gain a
jenyasd209 [6]

The step in the penetration testing life cycle is accomplished using rootkits or trojan horse programs is option a: maintain access.

<h3>What is maintaining access in penetration testing?</h3>

“Maintaining Access” is a stage of the  penetration testing life cycle and it is said to have a real purpose.

It is one that tends to allow the pentester to stay in the set systems until he get the information he need that is  valuable and then manages to take it successfully from the system.

Hence, The step in the penetration testing life cycle is accomplished using rootkits or trojan horse programs is option a: maintain access.

Learn more about penetration testing  from

brainly.com/question/26555003

#SPJ1

7 0
2 years ago
Other questions:
  • What is a relationship between a object and a class?
    6·1 answer
  • Write the definition of a function divide that takes four arguments and returns no value . The first two arguments are of type i
    8·1 answer
  • An example of a primary collision factor is
    6·2 answers
  • Which button could Pamela press in the Microsoft Word spell checker to make the word “colour” instantly change to “color” whenev
    11·1 answer
  • (15 POINTS) Integrated Circuits Of Made Up Of _____ That Carry The Electrical Current.
    10·1 answer
  • How do u make a bored builder
    8·2 answers
  • A magnetic disk drive requires a motor to position a read/write head over tracks of data on a spinning disk, (see fig. e4.4 in d
    8·1 answer
  • Who made the game Monopoly???
    10·2 answers
  • _____is used to organize and modify the properties of the current selection.
    6·1 answer
  • What is the address space of a computer with a 64-bit address bus?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!