This problem is part of our Ada Lovelace Day celebration. It is for practice only and will NOT count towards your grade!
(just have fun and use it to improve your skills: there is no submission deadline!)


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).

[ALD04] Latanya and Data Privacy

Latanya Sweeney is an American computer scientist known for her work on data privacy. In 2001, she became the first Black woman to earn a PhD in computer science at MIT!

Her research showed that removing names from records may not be enough to protect privacy. Other details, such as age or postal code, can sometimes be combined to identify people.

Your job is to help Latanya build a simple function that reduces the personal detail in a list of records.

The Problem

Implement the function protect_data(people). The parameter people is a list of tuples. Each tuple has exactly three elements:

(name, age, postal_code)

The function must return a new list of tuples of the form:

(identifier, age_group, masked_postal_code)

All three elements of each returned tuple are strings. You should make the necessary transformations (described below), but keeping the original record order.

The transformations are the following:

Identifier

For example, considering a people list [("Amadeu", 25, "1234-567"), ("B", 32, "4567-890")]:

Age group

The age should be replaced with the string corresponding to its interval, as shown in the following table:

Age interval Age group
[0, 10[ "0-10"
[10, 20[ "10-20"
[20, 30[ "20-30"
[30, 40[ "30-40"
[40, 50[ "40-50"
[50, 60[ "50-60"
[60, 70[ "60-70"
[70, 80[ "70-80"
[80, 90[ "80-90"
[90, 100] "90-100"

The notation [a, b[ includes a but excludes b. For example, age 10 belongs to [10, 20[ and therefore becomes "10-20".

Masked postal code

To mask the postal code, you should apply these rules: For example, "1234-567" becomes "1234-5**".

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ |people| ≤ 1000       number of records
1 ≤ |name| ≤ 100       characters in each name
Names contain letters only      
Ages are integers in the interval [0, 100[      
Postal codes follow the format "DDDD-DDD"      

Example Function Calls 1 Example Output 1
people = [
          ("Ana", 25, "1234-567"), 
          ("bruno", 32, "4567-890"),
          ("Carla", 29, "1234-599"),
          ("diogo", 40, "9876-543")
         ]
print(protect_data(people))
[
('AA#1', '20-30', '1234-5**'),
('BO#2', '30-40', '4567-8**'),
('CA#3', '20-30', '1234-5**'),
('DO#4', '40-50', '9876-5**')
]

Ana becomes "AA#1" because the first and last letters of "Ana" are both A, and she is in position 1.
Her age, 25, belongs to [20, 30[, and her postal code becomes "1234-5**".
Diogo's age is 40, which belongs to [40, 50[ because the left value is included.
"bruno" and "diogo" started with a lowercase letter, but their identifiers consider uppercase letters only.


Example Function Calls 2 Example Output 2
people = [
          ("A", 0, "0000-001"),
          ("Eva", 9, "0123-045"),
          ("Rui", 10, "1000-099"),
          ("Leo", 90, "9000-010"),
          ("Ivo", 99, "9999-999")
         ]
print(protect_data(people))
[
('AA#1', '0-10', '0000-0**'),
('EA#2', '0-10', '0123-0**'),
('RI#3', '10-20', '1000-0**'),
('LO#4', '90-100', '9000-0**'),
('IO#5', '90-100', '9999-9**')
]

This example shows boundary ages: 0 and 9 belong to [0, 10[, 10 belongs to [10, 20[, and 90 and 99 belong to [90, 100].
The one-character name "A" uses the same letter twice.


Introduction to Programming (CC1024)
DCC/FCUP - University of Porto