In: Computer Science
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.
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.
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.