Answered step by step
Verified Expert Solution
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',
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 belowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started