Question

In: Computer Science

Can anyone use python to solve this problem: Part B: List of lists The aim of...

Can anyone use python to solve this problem:

Part B: List of lists

The aim of Part B is to learn to work with list of lists. You may want to open the file lab05b_prelim.py in the editor so that you can follow the task description. The first part of the file lab05b_prelim.py defines a variable called datasets. The variable datasets is a list of 4 lists.

This part consists of 2 tasks.

Task 1: We ask you to type the following commands in the console and observe the output. This is to get yourselves familiarised with indexing in the list of lists as well as list processing.

  1. datasets[0]
  2. datasets[2]
  3. datasets[1][3]
  4. datasets[2][6]
  5. len(datasets)
  6. max(datasets[2])
  7. len(datasets[3])

Note that list processing is covered in Week 3A's lecture. See the Python example file list_processing.py in Week 3's lecture (filed under code_prelim_3A).

Task 2:

For this task, you are asked to create a list called summary_list. The number of entries in summary_list is the same as the number of lists in the variable datasets. The entries of the list summary_list is computed as follows:

summary_list[0] = minimum value in datasets[0] / number of entries in datasets[0]

summary_list[1] = minimum value in datasets[1] / number of entries in datasets[1]

and so on.

You are asked to write the Python code to compute summary_list automatically from the variable datasets. You can complete your work in lab05b_prelim.py. Note that your code should be able to work with any variable datasets which is a list of lists of numbers. That is, if the contents of the variable datasets change, then your code should still compute the correct summary_list. You can test that by commenting/uncommenting Lines 10-15 in the file to change the number of lists within the list of lists.

Solutions

Expert Solution

Task 1:

datasets=[[],[],[],[]]#create list of 4 lists
print(datasets[0])
print(datasets[2])
#print(datasets[1][3]) This gives error because there are no elements stored in list currently
#print(datasets[2][6]) This gives error because there are no elements stored in list currently
print(len(datasets))
#print(max(datasets[2])) This gives error because there are no elements stored in list currently to find max element
print(len(datasets[3]))

Task 2:

datasets=[[1,2,3],[4,5,6],[7,8,9,10],[12,12,14,45]]
summary_list=[]#based on number of entries are present in datasets list
for i in range(len(datasets)):
summary_list.append(0)#create one entry for each entry in dataset list

for i in range(len(datasets)):
summary_list[i]=min(datasets[i])/len(datasets[i])#compute summary_list

print("Summary list is:",summary_list)#print summary ist

Screenshots:

The screenshots are attached below for reference.

Please follow them for proper indentation and output. Please upvote my answer. Thank you.


Related Solutions

Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to represent a tic tac toe board, write code to check if the board has a winner.
Python: I am currently a function that will return a list of lists, with the frequency...
Python: I am currently a function that will return a list of lists, with the frequency and the zip code. However, I am having a difficult time organizing the list in decreasing order of frequency. We are asked to use sort () and sorted () instead of lambda. The function will find 5 digit zip codes, and when it sees a 9-digit zip code, the function needs to truncate the last 4 digits. The following is an example of the...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 2 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next =...
Can you solve part C Only becuse Part A&B is been solve Exercise 20-17 (Part Level...
Can you solve part C Only becuse Part A&B is been solve Exercise 20-17 (Part Level Submission) Splish Company sponsors a defined benefit pension plan for its 600 employees. The company’s actuary provided the following information about the plan. January 1, December 31, 2017 2017 2018 Projected benefit obligation $2,780,000 $3,626,200 $4,166,296 Accumulated benefit obligation 1,900,000 2,426,000 2,925,000 Plan assets (fair value and market-related asset value) 1,690,000 2,892,000 3,790,000 Accumulated net (gain) or loss (for purposes of the corridor calculation)...
PROGAMMING LANGUAGE: C++ Can anyone solve this assignment? Especially the extra credit part? Thanks. Please study...
PROGAMMING LANGUAGE: C++ Can anyone solve this assignment? Especially the extra credit part? Thanks. Please study the code 'Stack as Array example ' posted below. You need to implement a stack template, but this time implement the stack as a single linked list. The test of the class should be done with the same main function, slightly modified to declare a stack object and properly call the class functions. There is a helper file in the module that shows you...
For an application of your choice, describe the problem you aim to solve, design the necessary...
For an application of your choice, describe the problem you aim to solve, design the necessary classes, and implement your design using Java. Your programs should contain at least two classes, and a driver class in which you demonstrate the functionality of your application. You are required to submit the following documents at the completion of your project in Module 8: Documentation of the project, containing the algorithm, produced in pseudocode or flowchart, as well as the UML diagram representing...
USE PYTHON TO SOLVE THIS PROBLEM A bacteria culture grows exponentially. After 2 hours, the bacteria...
USE PYTHON TO SOLVE THIS PROBLEM A bacteria culture grows exponentially. After 2 hours, the bacteria count was 400 cells and after 6 hours, the bacteria count was 20,000 cells. a) Solve a system of equations to find (approximately) k and y0 (HINT: If will help to assume K is real in the symbols command) b) Use this to determine when the bacteria count reaches 2,000,000 (exact and approximate). c) Suppose 400 was the “initial” amount and 20,000 the count...
USE PYTHON TO SOLVE THIS PROBLEM A bacteria culture grows exponentially. After 2 hours, the bacteria...
USE PYTHON TO SOLVE THIS PROBLEM A bacteria culture grows exponentially. After 2 hours, the bacteria count was 400 cells and after 6 hours, the bacteria count was 10,000 cells. a) Solve a system of equations to find (approximately) k and y0 (HINT: If will help to assume K is real in the symbols command) b) Use this to determine when the bacteria count reaches 1,000,000 (exact and approximate). c) Suppose 400 was the “initial” amount and 10,000 the count...
In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT