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
Mila [183]
3 years ago
9

Write a function get_common_elems(lst1, lst2) that takes two lists of integers, lst1, and lst2, and returns a new list containin

g the elements in common between the two lists. You can assume that there are no repeated elements in the lists. Also, the ordering of the elements in the returned new list is not significant. The function signature is given below: def get_common_elems(lst1,lst2): sig : list (int),list (int) -> list(int) For example, a call to get_common_elems([5,1,4,3,6],[6,1,8,3]) will return the list 1, 3, 6. Hint: Think about how you can make use of the in operator. You only need to iterate over one of the lists.
Computers and Technology
1 answer:
zaharov [31]3 years ago
3 0

Answer:

def get_common_elems(lst1, lst2):

   common_list = []

   for e in lst1:

       if e in lst2:

           common_list.append(e)

   return common_list

Explanation:

Create a function called get_common_elems that takes two lists, lst1, and lst2

Inside the function:

Create an empty list to hold the common elements

Initialize a for loop that iterates through the lst1.

If an element in lst1 is also in the lst2, append that element to the common_list

When the loop is done, return the common_list

You might be interested in
Which term is defined as an exploit that takes place before the security community or software developer knows about the vulnera
Natasha_Volkova [10]

Answer:

A zero-day attack.

Explanation:

A Zero-day vulnerability is a computer-software vulnerability that is unknown to, or unaddressed by, the security community or software developer or even the vendor of the target software. Until the vulnerability is mitigated, hackers can exploit it to adversely affect computer programs, data, additional computers or a network.

An exploit directed at a software with zero-day vulnerability & exploiting this vulnerability is called a zero-day exploit, or zero-day attack.

3 0
3 years ago
If the cpu is fast but the bus speed is slow, that condition is called?
yanalaym [24]
A slow processors but the need more bytes
5 0
2 years ago
LAB: Praising dates
blsea [12.9K]

Answer:

Explanation:

The following is the entire modified code, it takes in the date as an input and continues changing the dates to the desired format. If the input format is wrong it says "Wrong Format" and requests another input. If -1 is passed as an input the program terminates.

        import java.util.Scanner;

        class DateParser {

public static int getMonthAsInt(String monthString) {

        int monthInt;

        switch (monthString) {

            case "January" :

                monthInt = 1;

                break;

            case "February":

                monthInt = 2;

                break;

            case "March":

                monthInt = 3;

                break;

            case "April":

                monthInt = 4;

                break;

            case "May":

                monthInt = 5;

                break;

            case "June":

                monthInt = 6;

                break;

            case "July":

                monthInt = 7;

                break;

            case "August":

                monthInt = 8;

                break;

            case "September":

                monthInt = 9;

                break;

            case "October":

                monthInt = 10;

                break;

            case "November":

                monthInt = 11;

                break;

            case "December":

                monthInt = 12;

                break;

            default:

                monthInt = 0;

                }

        return monthInt;

       }

        public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

               // TODO: Read dates from input, parse the dates to find the one

        // in the correct format, and output in m/d/yyyy format  

 

                String date = "";

                while (!date.equals("-1")) {

                    String month = "";

                    String day = "";

                    String year = "";

                    System.out.println("Enter date:");

                    date = scnr.nextLine();

                    try {

                        year = date.substring((date.length()-4), date.length());

                        if (Character.isDigit(date.charAt(date.length()-8))) {

                            day = date.substring((date.length()-8), date.length()-6);

                            month = date.substring(0, date.length()-9);

                        } else {

                            day = date.substring((date.length()-7), date.length()-6);

                            month = date.substring(0, date.length()-8);

                        }

                        if ((year.length() == 4) && (day.length() > 0) && (day.length() <= 2) && (month.length() >= 3)) {

                            System.out.println(getMonthAsInt(month) + "/" + day + "/" + year);

                        } else {

                            System.out.println("Wrong Format");

                        }

                    } catch (Exception e) {

                        System.out.println("Wrong Format");

                    }

                }    

        }

}

4 0
3 years ago
Ask the user to type in an integer greater than 50 and assign it to a variable called x. Write a program to calculate the sum of
Zinaida [17]

Answer:

The solution in Python is as follows:

<em>num = int(input("Number: "))</em>

<em>if num>50:</em>

<em>     sum = 0</em>

<em>     count = 0</em>

<em>     for i in range(1,num):</em>

<em>          count = count + 1</em>

<em>          sum = sum + i**2</em>

<em>          if sum > num:</em>

<em>               sum = sum - i**2</em>

<em>               count = count - 1</em>

<em>               break;</em>

<em>    </em>

<em>     print("Sum: "+str(sum))</em>

<em>     print("Numbers: "+str(count))</em>

<em>else:</em>

<em>     print("Number must be greater than 50")</em>

<em />

Explanation:

The condition stated in the question do not conform with the example. The question says, the loop should stop when sum > x.

But:

When x = 100 and sum = 91, the program loop should not stop because 91 is not greater than 100.

However, I'll answer based on the example given in the question.

This prompts user for number

num = int(input("Number: "))

The following if condition is executed if number is greater than 50

if num>50:

This initializes sum to 0

    sum = 0

This initializes count to 0

    count = 0

The iterates through the inputted number (e.g. 100)

    for i in range(1,num):

This increases the count

         count = count + 1

This calculates the sum of square of the positive integer

         sum = sum + i**2

The following removes excess number from the sum

<em>          if sum > num:</em>

<em>               sum = sum - i**2</em>

<em>               count = count - 1</em>

<em>               break;</em>

This prints the calculated sum    

    print("Sum: "+str(sum))

This prints the count of number used

    print("Numbers: "+str(count))

The following is executed if user input is less than 50

<em>else:</em>

<em>     print("Number must be greater than 50")</em>

<em />

<em></em>

3 0
3 years ago
How to change default search engine in internet explorer 10?
ser-zykov [4K]
Settings > view advanced settings > change search engine > Google search > set as default
7 0
3 years ago
Other questions:
  • Which destination ip address is used when an ipv6 host sends a dhcpv6 solicit message to locate a dhcpv6 server?
    15·1 answer
  • A (n) _____ exposure is a short term or brief exposure that may create an immediate health hazard
    9·1 answer
  • The process of using a computer to write, design, and assemble documents is called A. desktop publishing. B. scanning. C. consul
    7·1 answer
  • A microphone plugs into what type of connector
    5·2 answers
  • A filter is a camera accessory that is mounted on the optical path of the lens.<br> true or false
    6·2 answers
  • D Question 9 What is output by the following?
    5·1 answer
  • Which of the following is true about media production? A. All media elements contain a certain type of editorial viewpoint. B. P
    10·1 answer
  • What is hub.pls ans from pic. for computers​
    9·2 answers
  • Identify the following verb by number and person by checking on the appropriate boxes.
    15·2 answers
  • A service that enables a customer to build and run their own applications but doesn't include extensive access to hardware and m
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!