Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source. Nested lists The “*” operator List slices The “+=” operator A list filter A list operation that is legal but does the "wrong" thing, not what the programmer expects Provide the Python code and output for your program and all your examples.

Answers

Answer 1
Answer:

Lists are used in Python to hold multiple values in one variable

(a) Nested list

A nested list is simply a list of list; i.e. a list that contains another list.

It is also called a 2 dimensional list.

An example is:

nested_list = [[ 1, 2, 3, 4]  , [ 5, 6, 7]]

(b) The “*” operator

The "*" operator is used to calculate the product of numerical values.

An example is:

num1 = num2 * num3

List slices

This is used to get some parts of a list; it is done using the ":" sign

Take for instance, you want to get the elements from the 3rd to the 5th index of a list

An example is:

firstList = [1, 2 ,3, 4, 5, 6, 7]

secondList = firstList[2:5]

The “+=” operator

This is used to add and assign values to variables

An example is:

num1 = 5

num2 = 3

num2 += num1

A list filter

This is used to return some elements of a list based on certain condition called filter.

An example that prints the even elements of a list is:

firstList = [1, 2 ,3, 4, 5, 6, 7]

print(list(filter(lambda x: x % 2 == 0, firstList)))

A valid but wrong list operation

The following operation is to return a single list, but instead it returns as many lists as possible

def oneList(x, myList=[]):

   myList.append(x)

   print(myList)

oneList(3)

oneList(4)

Read more about Python listsat:

brainly.com/question/16397886


Related Questions

Describe what happens at every step of our network model, when a node on one network establishes a TCP connection with a node on another network. You can assume that the two networks are both connected to the same router.Your submission must include a detailed explanation of the following: Physical layer Data link layer Network layer Transport layer MAC address IP address TCP port Checksum check Routing table TTL
What is the earliest version of the present day Internet?
Jimmy Fallon's persona when he is outside the White House can best be characterized as:A. humble and excited.B. outrageous and crazy.C. stern and authoritative.D. dark and serious.
Define a function below called average_strings. The function takes one argument: a list of strings. Complete the function so that it returns the average length of the strings in the list. An empty list should have an average of zero. Hint: don't forget that in order to get a string's length, you need the len function.
Define the function isEven which returns True, if a given number is even and returns False, if the number is odd. Execute the statement isEven(43) and display the output.

Which vendor did IBM select to create the operating system for the IBM PC?

Answers

The Answer Is: "Microsoft".

A network engineer is troubleshooting a small LAN network with one border router, GW01 that connects to the Internet Service Provider’s (ISP) network. GW01 uses its Serial 0/2/1 interface to connect to the ISP’s router. Everyone on the LAN network lost connectivity to the Internet. Upon troubleshooting the issue, the network engineer notices the following message after typing show ip route. Gateway of last resort required but not set. What do you suggest the network engineer do to rectify this issue? Assume the problem is only on the organization’s LAN side of the network. Provide as much information as possible including specific commands and all required parameters.

Answers

Answer:

Create a default route on the border router. Check the NAT configuration and network addresses.

Explanation:

The LAN or local area network is a network meant for a small geographic area, ranging from a small home office to office building.

For a LAN to be connected to the internet, it is subscribed to a ISP. The ISP provides the internet/ global WAN resources to the LAN. The border router or stub is configured with a gateway of last resort or default route to route packets to the WAN network and a Network address translation, NAT, is used for a large LAN.

The syntax for default route configuration on the border router is;

Router(config)# IP route 0.0.0.0 0.0.0.0 s0/0/1

A _____, or spider, is a search engine program that automatically searches the web to find new websites and update information about old websites. ​a.
​crab

b.
web ​robot

c.
​database

d.
​runner

Answers

Answer: B) Web robot

Explanation:

Web robot or spider is the search engine program which automatically visit the new web site and update the information. Basically, it is the internet bot that helps in store the information from the search engine to the index.

Spider searches the web site and read the information in their given page for creating the entries from search engine.

Web robot is also known as web crawler, this type of programs are use by different search engine that automatically download and update the web content on web sites.  

1) The program reads an integer, that must be changed to read a floating point. 2) You will need to move that number into a floating point register and then that number must be copied into an integer register. 3) You will need to extract the exponent from the integer register and stored in another register. 4) You will need to insert the Implied b

Answers

Answer:

1. Get the number

2. Declare a variable to store the sum and set it to 0

3. Repeat the next two steps till the number is not 0

4. Get the rightmost digit of the number with help of remainder ‘%’ operator by dividing it with 10 and add it to sum.

5. Divide the number by 10 with help of ‘/’ operator

6. Print or return the sum

# include<iostream>

using namespace std;

/* Function to get sum of digits */

class gfg

{

   public:

   int getSum(float n)

   {

   float sum = 0 ;

   while (n != 0)

   {

    sum = sum + n % 10;

    n = n/10;

   }

return sum;

}

};

//driver code

int main()

{

gfg g;

float n = 687;  

cout<< g.getSum(n);

return 0;

}

Explanation:

Implement the function calcWordFrequencies() that uses a single prompt to read a list of words (separated by spaces). Then, the function outputs those words and their frequencies to the console.Ex: If the prompt input is:

hey hi Mark hi mark
the console output is:

hey 1
hi 2
Mark 1
hi 2
mark 1

Answers

Answer:

JavaScript code is given below

Explanation:

function calcWordFrequencies() {

   var words = prompt("Enter the sentence below").split(" ");

   var unique_words = [], freqencies = [], count = 0;

   for (var i = 0; i < words.length; i++) {

       var found = false;

       for (var j = 0; j < count; j++) {

           if (words[i] === unique_words[j]) {

               freqencies[j] = freqencies[j] + 1;

               found = true;

           }

       }

       if (!found) {

           unique_words[count] = words[i];

           freqencies[count] = 1;

           count++;

       }

   }

   for (var i = 0; i < words.length; i++) {

       var result = 0;

       for (var j = 0; j < count; j++) {

           if (words[i] === unique_words[j]) {

               result = freqencies[j];

               break;

           }

       }

       console.log(words[i] + " " + result);

   }

}

Where does execution resume after an exception has been thrown and caught?

Answers

Answer:

The execution resumes in the finally block if one exists or otherwise from the next statement following the try...catch block.

Explanation:

Once an exception has been thrown and caught in the code, the execution continues with the statements in the finally block if one exists. If there is no finally block defined then execution resumes from the next statement following the try... catch block. For example:

try{

//An exception is raised

}

catch (Exception e){

//Exception is handled

}

System.out.println("After try...catch");

In this code segment, the next statement to be executed after catch is the System.out.println();