Problem

Python

The following is the name list of all people in a hypothetical class.

Christian-Andrew Bagby-wright
Matthew Chrysler
Niyousha Davachi
Pauline Dredger
Marcos Guillen
Lauren Kuffel
Shashank Kumbhare
Hany Mahdy
Sarah Moorman
Andrew Myers
Joshua Osborne
Rebecca Proni
Amir Shahmoradi
Carolina Vedovato

We want to create a dictionary of members of this class with individuals’ full names serving as dictionary keys, and their roles in class as the corresponding values of the keys. The naive way of generating this dictionary would be to use one of the methods for generating dictionary discussed in the lecture notes. For example,

class_dict  = { 
            , 'Christian-Andrew Bagby-wright' : 'student'
            , 'Matthew Chrysler'              : 'student'
            , 'Niyousha Davachi'              : 'student'
            , 'Pauline Dredger'               : 'student'
            , 'Marcos Guillen'                : 'student'
            , 'Lauren Kuffel'                 : 'student'
            , 'Shashank Kumbhare'             : 'student'
            , 'Hany Mahdy'                    : 'student'
            , 'Sarah Moorman'                 : 'student'
            , 'Andrew Myers'                  : 'student'
            , 'Joshua Osborne'                : 'student'
            , 'Rebecca Proni'                 : 'student'
            , 'Amir Shahmoradi'               : 'instructor'
            , 'Carolina Vedovato'             : 'student'
            }

However, the problem is that, except Amir, the instructor, everyone else has a student role in this class. So it would be a very painful process to type all ‘student’ values by hand manually. Now, the goal is to come up with a shortcut method that avoids the aforementioned problem.

Can you find a way of creating this dictionary, without having to type the value ‘student’ 14 times? Note that to achieve this, you don’t need anything beyond what you learned in the lecture notes. (Hint: Have a look at the section for simultaneous assignments in the lecture notes.)

Comments