Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the starter code # starter code students = ['Tommy', 'Kitty', 'Jessie', 'Chester', 'Curie', 'Darwing', 'Nancy', 'Sue', 'Peter', 'Andrew', 'Karren', 'Charles', 'Nikhil', 'Justin', 'Astha',

image text in transcribed

Here is the starter code

# starter code

students = ['Tommy', 'Kitty', 'Jessie', 'Chester', 'Curie', 'Darwing', 'Nancy', 'Sue', 'Peter', 'Andrew', 'Karren', 'Charles', 'Nikhil', 'Justin', 'Astha', 'Victor', 'Samuel', 'Olivia', 'Tony']

assignment = [2, 5, 5, 7, 1, 5, 2, 7, 5, 1, 1, 1, 2, 1, 5, 2, 7, 2, 7]

# write your code below

Please give brief explanation as well as code, also I want full credit so the code should be comprehension implementation with no loop statements. Thanks

This problem presents a common data analysis task that assigns data into differet groups based on the grouping defined by a list of integers. Suppose we have a list of students: students=[Tommy,Kitty,Jessie,Chester,Curie,Darwing,Nancy,Sue,Peter,Andrew,Karren,Charles,Nikhil,Justin,Astha,Victor,Samuel,Olivia,Tony] We are going to assign them into 4 groups. The group identity of each student is specified by the integer at the same index position in a list named assignment: assignment=[2,5,5,7,1,5,2,7,5,1,1,1,2,1,5,2,7,2,7] This list represents a grouping rule that assigns 'Tommy' to group 2, 'Kitty' to group 5, to group 5 , and so on. Write code to produce a dictionary whose values are each a list that contains all students assigned to the corresponding group. The expected output is \{'Group 1': ['Curie', 'Andrew', 'Karren', 'Charles', 'Justin'], 'Group 2': ['Tommy', 'Nancy', 'Nikhil', 'Victor', 'Olivia'], 'Group 5': ['Kitty', 'Jessie', 'Darwing', 'Peter', 'Astha'], 'Group 7': ['Chester', 'Sue', 'Samuel', 'Tony'] Hint: - The keys, i.e., 'Group 1', 'Group 2', 'Group 5', and 'Group 7', can be composed by string formatting with group identity. - Use set() to remove duplicate group identifiers, create a list counterpart, and sort distinct identifiers in ascending order. Full credits will be awarded only if your answer is a comprehension implemention. Implementations with loop statements can only get at most 80% of full marks. \# starter code students =[ 'Tommy', 'Kitty', 'Jessie', 'Chester', 'Curie', 'Darwing', 'Nancy', 'Sue', 'Peter', 'Andrew', 'Karren', 'Charles', 'Nikhil', 'Justin', 'Astha', 'Victor', 'Samuel', 'olivia', 'Tony'] assignment =[2,5,5,7,1,5,2,7,5,1,1,1,2,1,5,2,7,2,7] \# write your code below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

5. Give examples of variations in contextual rules.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago