Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There's a lot of information, so PLEASE READ CAREFULLY!! PYTHON3; DO NOT IMPORT ANY PACKAGES FOLLOW THE REQUIREMENTS: DO NOT USE FOR/WHILE LOOPS Data Science

There's a lot of information, so PLEASE READ CAREFULLY!!

PYTHON3; DO NOT IMPORT ANY PACKAGES

FOLLOW THE REQUIREMENTS: DO NOT USE FOR/WHILE LOOPS

Data Science department decides to create a @dsc.ucla.edu email for undergraduate students in Data Science major. Suppose the department has access to student information organized as a sequence of (name, class_year, college, major_code) tuples. You can assume the following for each attribute in the tuple:

  1. name is a string of full name, in the format of Firstname Lastname or Firstname Middlename Lastname.

  2. class_year is a 4-digit integer, representing a valid year.

  3. college is a string, and each college has a 2-character abbreviation. All combinations are: (Revelle, RC), (Muir, MC), (Marshall, TM) (Warren, WC), (Roosevelt, ER), (Sixth, SX), (Seventh, SV). Only the full name of the college will be passed as argument, and the abbreviation will only be used to generate the email address.

  4. major_code is a 4-character string from this list (2 uppercase letters and 2 digits).

  5. All letters in name and college can be either uppercase or lowercase.

Given a tuple described about, your function will extract:

  • the first 3 letters of the first name (or full first name if its shorter than 3 characters)

  • the first 6 letters of the last name (or full last name if its shorter than 6 characters)

  • the last 2 digits of the class_year (assume its a valid 4 digit year)

  • the 2-character abbreviation of the college

Then, your function should concatenate them together, and add @dsc.ucla.edu at the end. Note that the generated email address should be all lowercase.

Example:

longfirstname longlastname, 1990, marshall -> lonlongla90tm@dsc.ucla.edu

FIRST MIDDLE LAST, 2022, REVELLE -> firlast22rc@dsc.ucla.edu

However, before generating the email address, this function should filter out students in other departments (i.e. students not in Data Science major (code DS25)). In addition, this function takes a list of class years (years) as argument, and this function should only generate email addresses for students who are in the specified class years.

After generating email addresses for all students that fulfill the requirements, this function returns a dictionary, where the keys are the names of students, and the values are the generated email addresses.

Requirements: No for/while

Note:

  1. Since the rules of the email address generation from tuple are complicated, defining the rules with an inner function would be more convenient.

  2. To populate the output dictionary, you can either define an inner function/lambda function, or use dict().

def create_dsc_email(students, years):

"""

>>> students = [ \

("First Middle Last", 2022, "revelle", "DS25"), \

("hi HELLO", 2022, "seventh", "DS25"), \

("Computer Science", 2021, "Warren", "CS25"), \

("longfirstname longlastname", 1990, "Marshall", "DS25") \

]

>>> create_dsc_email(students, [2022])

{'First Middle Last': 'firlast22rc@dsc.ucla.edu', \

'hi HELLO': 'hihello22sv@dsc.ucla.edu'}

>>> create_dsc_email(students, [1990, 2021])

{'longfirstname longlastname': 'lonlongla90tm@dsc.ucla.edu'}

>>> create_dsc_email(students, [])

{}

"""

# YOUR CODE GOES HERE #

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

5-56. Trudy, when she first saw the bull pawing the ground, ran.

Answered: 1 week ago

Question

Explain the Neolithic age compared to the paleolithic age ?

Answered: 1 week ago

Question

What is loss of bone density and strength as ?

Answered: 1 week ago

Question

a. How will the leader be selected?

Answered: 1 week ago