Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ms. Frizzle has a list of tuples, one tuple for each student in her class. Each tuple contains the name of a student (type str),

Ms. Frizzle has a list of tuples, one tuple for each student in her class. Each tuple contains the name of a student (type str), the perm number (of type int) of that student, and a boolean value to indicate whether the student was present that day (type bool). Unfortunately, each tuple got jumbled such that the name, perm number, and attendance status are not necessarily in that order. For example, one tuple is (True, 65473, 'Sarah'), and Ms. Frizzle would like it to read ['Sarah', 65473, True].

Help Ms. Frizzle write a function unscrambleTuples() that takes in a parameter list_of_tuples and returns a list of lists that stores the values in the way Ms.Frizzle wants: students name, student ID, attendance flag ([str, int, bool]).

For example, for a list that contains a single tuple, unscrambleTuples([(12345, False, 'Frodo')]) should return [['Frodo', 12345, False]].

Another example: unscrambleTuples([('Sarah', 65473, True), (True, 1234, 'Beyonce'), (False, 'Molly',2344)]) should return [['Sarah', 65473, True], ['Beyonce', 1234, True], ['Molly', 2344, False]].

IMPORTANT: When you create an empty list, you cannot directly index it, because it contains no elements. If you use append(), it adds elements to the end of the list, which might not be the order that you want. Sometimes, instead of an empty list, you can create a list with the paceholder (stub) values, which then gives you the ability to index (and change) those values directly.

def unscrambleTuples(list_of_tuples): """ Given a list of tuples that contain values of type string, int, and bool, unscramble the values to create a new list that turns each tuple from the list_of_tuples into a list with the values arranged by type as follows: [str, int, bool]. """ return "stub"

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions