Skip to content

Commit f1133b3

Browse files
authored
Create 11 Contact List
1 parent d76ce4f commit f1133b3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

1 Python/labs/11 Contact List

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# Lab 11: Contact List
3+
4+
5+
Let's build a program to manage a list of contacts. To start, we'll build a CSV ('comma separated values') together, and go over how to load that file. Headers might consist of `name`, `favorite fruit`, `favorite color`. Open the CSV, convert the lines of text into a **list of dictionaries**, one dictionary for each user. The text in the header represents the **keys**, the text in the other lines represent the **values**.
6+
7+
```python
8+
with open('contacts.csv', 'r') as file:
9+
lines = file.read().split('\n')
10+
print(lines)
11+
```
12+
13+
Once you've processed the file, your list of contacts will look something like this...
14+
```python
15+
contacts = [
16+
{'name':'matthew', 'favorite fruit':'blackberries', 'favorite color':'orange'},
17+
{'name':'sam', 'favorite fruit':'pineapple' ...}
18+
]
19+
```
20+
21+
*Note: There is a `csv` library in Python that will do much of this for you. It is what you would use normally in a project, but for this lab you need to write all the logic yourself.*
22+
23+
## Version 2
24+
25+
Implement a CRUD REPL
26+
27+
- **C**reate a record: ask the user for each attribute, add a new contact to your contact list with the attributes that the user entered.
28+
- **R**etrieve a record: ask the user for the contact's name, find the user with the given name, and display their information
29+
- **U**pdate a record: ask the user for the contact's name, then for which attribute of the user they'd like to update and the value of the attribute they'd like to set.
30+
- **D**elete a record: ask the user for the contact's name, remove the contact with the given name from the contact list.
31+
32+
## Version 3
33+
34+
When REPL loop finishes, write the updated contact info to the CSV file to be saved. I highly recommend saving a backup `contacts.csv` because you likely won't write it correctly the first time.
35+

0 commit comments

Comments
 (0)