Skip to content

Commit ffac32f

Browse files
committed
lab11 in progress
1 parent 6f881a9 commit ffac32f

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name,favorite_fruit,favorite_color
2+
daniel,kiwi,green
3+
bob,apple,blue
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
#==========================================================
3+
4+
# contact_info = {'David': '5551234', 'Alice': '6662345'}
5+
# with open('phonebook.txt', 'w') as phone_book_file:
6+
# for name, number in phonebook.items():
7+
# line = f'{name} {number}\n'
8+
# phone_book_file.write(line)
9+
10+
11+
#==========================================================
12+
13+
# with open('phonebook.txt') as phone_book_file:
14+
# phone_book_data = phone_book_file.read().split('\n')
15+
16+
# phone_book = {}
17+
# for line in phone_book_data:
18+
# name, number = line.split()
19+
# phone_book[name] = number
20+
21+
#==========================================================
22+
# Version1
23+
#==========================================================
24+
25+
import pprint
26+
27+
with open('contact_list.csv', 'r') as file:
28+
lines = file.read().split('\n')
29+
# print('lines: ', lines)
30+
31+
contacts_list = []
32+
33+
headers = lines[0].split(",")
34+
# print("headers: ", headers)
35+
36+
for l in range(1, len(lines)):
37+
the_name, the_favorite_fruit, the_favorite_color = lines[l].split(",")
38+
# print(name, favorite_fruit, favorite_color)
39+
40+
contact_dict = {
41+
headers[0]: the_name,
42+
headers[1]: the_favorite_fruit,
43+
headers[2]: the_favorite_color
44+
45+
}
46+
print(contact_dict)
47+
48+
contacts_list.append(contact_dict)
49+
pprint.pprint(contacts_list)
50+
51+
# contacts['name'] = name
52+
# contacts['favorite_fruit'] = favorite_fruit
53+
# contacts['favorite_color'] = favorite_color
54+
55+
# print(contacts)
56+
57+
#==========================================================
58+
# Version2
59+
#==========================================================
60+
61+
# def record():
62+
# get_info = []
63+
# get_name = input("Add a name to the contact list: ")
64+
# get_fruit = input(f"What is {get_name}'s favorite fruit?: ")
65+
# get_color = input(f"What is {get_name}'s favorite color?: ")
66+
# get_info.append(get_name)
67+
# get_info.append(get_fruit)
68+
# get_info.append(get_color)
69+
# # print(get_info)
70+
71+
# record()
72+
73+
# with open('contact_list.csv', 'r') as file:
74+
# lines = file.write(get_info)
75+
76+
77+
#==========================================================
78+
# Version3
79+
#==========================================================

code/daniel/lab11-contact_list/phonebook.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)