Question: Question 2 (5 points): Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a4q2-starter.py you are given a

 Question 2 (5 points): Purpose: To practice creating and manipulating listswith list comprehensions. Degree of Difficulty: Mostly Easy In a4q2-starter.py you are

Question 2 (5 points): Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a4q2-starter.py you are given a definition of a list of lists. Each sublist contains three pieces of in- formation on one famous prairie pirate - their pirate name, the number of sacks of assorted grains they have plundered from unsuspecting farmers in the last year, and a Boolean value indicating whether they Like parrots. Create the following list comprehensions where indicated by comments in the provided file a4q2-starter.py. Note that you only need to create the appropriate list comprehensions, you do not need to print them out (though you may want to for testing purposes). (a) Use a single list comprehension to create a list of strings of the pirate names who plundered more than 400 sacks of assorted grains. (b) Use a single list comprehension to create a list of strings of the pirate names who don't like parrots. (c) Suppose that the average market value of a sack of grain is $42. Use a single list comprehension to create a list of integers of the market values of each pirate's grain. (d) Use a single list comprehension to create a list of lists where each sublist consists of a pirate's name, and the value of his/her plundered sacks of grain (calculate grain values as in part (c)), but only include those pirates who like parrots. What to Hand In Rename your completed a4q2-starter.py file to a4q2.py and submit it. Evaluation -1 mark for missing name, NSID and student number at top of file 1 mark each for parts (a), (b), and (c). 2 marks for part (d). prairie_pirates = [ ['Tractor Jack', 1000, True], ['Plowshare Pete', 950, False], ['Prairie Lily', 245, True], ['Red River Rosie', 350, True], ['Mad Athabasca McArthur', 842, False}, ['Assiniboine Sally', 620, True], ['Thresher Tom', 150, True], ['Cranky Canola Carl', 499, False] # part a) best_plunderers = [] # Write your list comprehension for part (a) here. # part b) parrot_haters = [] # Write your list comprehension for part (b) here. # part c) plunder_values = [] # Write your list comprehension for part (c) here. # part d) names_and_plunder_values = [] # Write your list comprehension for part (d) here. print(best_plunderers) print (parrot_haters) print (plunder_values) print(names_and_plunder_values)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!