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
Vladimir79 [104]
3 years ago
6

The aim of this activity is to implement an algorithm that returns the union of elements in a collection. Although working with

sets is quick and easy in Python, sometimes we might want to find the union between two lists. Create a function called unite_lists, which uses a loop to go through both lists and return common elements. Do not use the built-in set function.
Computers and Technology
1 answer:
shusha [124]3 years ago
3 0

Answer:

The function in Python is as follows:

def unite_lists(A, B):

   union = []

   for elem in A:

       if elem in B:

           union.append(elem)

   return union

Explanation:

This defines the function

def unite_lists(A, B):

This initializes an empty list for the union list

   union = []

This iterates through list A

   for elem in A:

This checks if the item in list A is in list B

       if elem in B:

If it is present, the item is appended to the union list

           union.append(elem)

This returns the union of the two lists

   return union

You might be interested in
Write a loop that reads strings from standard input where the string is either "land", "air", or "water". The loop terminates wh
____ [38]

Answer:

count_land = count_air = count_water = 0

while True:

   s = input("Enter a string: ")

   if s == "xxxxx":

       break

   else:

       if s == "land":

           count_land += 1

       elif s == "air":

           count_air += 1

       elif s == "water":

           count_water += 1

print("land: " + str(count_land))

print("air: " + str(count_air))

print("water: " + str(count_water))

Explanation:

*The code is in Python

Initialize the variables

Create a while loop that iterates until a specific condition is met. Inside the loop, ask the user to enter the string. If it is "xxxxx", stop the loop. Otherwise, check if it is "land", "air", or "water". If it is one of the given strings, increment its counter by 1

When the loop is done, print the number of strings entered in the required format

4 0
3 years ago
What keeps unauthorized internet users out of private intranets?
Kruka [31]
I think coders put in codes. Sry if that does not help.
8 0
3 years ago
Six causes of data lost
Serhud [2]
Hard drive failures

Accidental deletions

Computer viruses and malware infections



Power failures
6 0
3 years ago
Why was the television the first audio visual device that changed the way people see entertainment?
Daniel [21]
It was  not.   Movies   then  talking movies  were   before television.

7 0
3 years ago
Consider the following code segment. int[][] arr = {{3, 2, 1}, {4, 3, 5}}; for (int row = 0; row < arr.length; row++) { for (
ludmilkaskok [199]

Answer:

Condition one - 1 time

Condition two - 2 times

Explanation:

Given

The above code segment

Required

Determine the number of times each print statement is executed

For condition one:

The if condition required to print the statement is:  <em>if (arr[row][col] >= arr[row][col - 1]) </em>

<em />

For the given data array, this condition is true only once, when

row = 1  and  col = 2

i.e.

<em>if(arr[row][col] >= arr[row][col - 1]) </em>

=> <em>arr[1][2] >= arr[1][2 - 1]</em>

=> <em>arr[1][2] >= arr[1][1]</em>

<em>=> 5 >= 3 ---- True</em>

<em />

The statement is false for other elements of the array

Hence, Condition one is printed once

<em />

<em />

For condition two:

The if condition required to print the statement is:  <em>if (arr[row][col] % 2 == 0) </em>

<em />

The condition checks if the array element is divisible by 2.

For the given data array, this condition is true only two times, when

row = 0  and  col = 1

row = 1  and  col = 0

i.e.

<em>if (arr[row][col] % 2 == 0) </em>

<em>When </em>row = 0  and  col = 1

<em>=>arr[0][1] % 2 == 0</em>

<em>=>2 % 2 == 0 --- True</em>

<em />

<em>When </em>row = 1  and  col = 0

<em>=>arr[1][0] % 2 == 0</em>

<em>=> 4 % 2 == 0 --- True</em>

<em />

<em />

The statement is false for other elements of the array

Hence, Condition two is printed twice

3 0
3 years ago
Other questions:
  • String word = “Awesome”;
    9·2 answers
  • What is the slogan of the sociological school of criticism ?​
    9·1 answer
  • If I Uninstall Nba 2k 19 from my ps4 will my career be gone forever?​
    5·2 answers
  • You are required to design a 4-bit even up-counter using D flip flop by converting combinational circuit to sequential circuit.
    15·1 answer
  • Anyone free to inbox me plz....​
    6·2 answers
  • Select the correct statement(s) regarding partial mesh networks.
    5·1 answer
  • Select the correct answer.
    14·2 answers
  • Write a program that reads a string of characters, pushing each character onto a stack as it is read and simultaneously adding i
    5·1 answer
  • When writing code, how can printing be useful?
    15·1 answer
  • HELP ME PLEASE ASAP
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!