Smart Contact Manager
Part of the Logic & Flow section of Coddy's Python journey — lesson 76 of 78.
Challenge
MediumCreate a function named organize_contacts that processes a list of contact dictionaries to create a clean contact database.
Each contact dictionary in the input list has these keys:
name: The person's nameemail: The person's email addressphone: The person's phone number
Your function should:
- Remove duplicate contacts (contacts with the same email or phone number), keeping the first occurrence
- Standardize all emails to lowercase
- Filter out contacts with invalid email addresses
- Filter out contacts with invalid phone numbers
- Return a list of cleaned contact dictionaries
Validation rules:
- Valid email: Must contain '@' and '.', and must not have spaces
- Valid phone: Must contain exactly 10 digits (ignore non-digit characters like dashes or parentheses)
For cleaning phone numbers, you should use Python's str.isdigit() method to extract only the numeric digits from phone numbers. This method returns True if a character is a digit (0-9) and False otherwise, making it perfect for filtering out non-digit characters.
Example Input:
contacts = [
{"name": "John Doe", "email": "john@email.com", "phone": "123-456-7890"}
]Expected Output:
[
{"name": "John Doe", "email": "john@email.com", "phone": "1234567890"}
]Try it yourself
def organize_contacts(contact_list):
# Your solution here
# 1. Create helper functions for validation
# - Function to validate email format
# - Function to clean and validate phone numbers
# 2. Process each contact
# - Clean email (lowercase) and phone (digits only)
# - Check if email and phone are valid
# - Check for duplicates
# 3. Return the clean contact list
passAll lessons in Logic & Flow
1Variables Exploration
ConstantsMultiple Variable AssignmentsSwapping VariablesPlaceholder VariablesRound NumbersList Casting4Contact Book Application
Display MenuAdd Contact7Sets Part 2
Mathematical Operations Part 1Mathematical Operations Part 2Recap - Treasure HuntSubsets and SupersetsIterating Over SetsRecap - Tournament Tracker2Dictionaries Part 1
What is a Dictionary?Creating a DictionaryAccessing ValuesModifying DictionariesRecap - Recipe Manager5Advanced Decision Making
Ternary OperatorMembership ChecksIdentity ChecksIndentation ErrorsRecap - Vacation Filter8Student Records Manager
Project OverviewAdd Student11Advanced Functions
Returning Multiple ValuesLambda Functions Part 1Lambda Functions Part 2Recap Challenge - Lambda SortRecursive Functions Part 1Recursive Functions Part 2Recap - Sum Nested List14Higher-Order Functions
The Map FunctionThe Filter FunctionRecap - Email ValidatorRecap - Number Processor3Dictionaries Part 2
Dictionary MethodsNested DictionariesChecking for KeysLooping Through DictionariesRecap - Frequency Counter9Advanced Data Aggregation
Using SumFinding Minimum and MaximumSorting Data EfficientlyRecap - Dictionary Sorter