Skip to content

Commit f9527e6

Browse files
committed
lab11 v1
1 parent 51b5cf0 commit f9527e6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

code/jonpan/contacts.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id,first_name,last_name,email,gender,ip_address
2+
1,Cello,Lorenzo,[email protected],Male,61.139.122.253
3+
2,Felita,Lawford,[email protected],Female,103.62.148.69
4+
3,Gene,Waterson,[email protected],Female,177.133.78.160
5+
4,Vitia,Cumbers,[email protected],Female,242.19.105.246
6+
5,Dalston,Smitham,[email protected],Male,253.115.85.93

code/jonpan/lab11_v1.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
with open('contacts.csv', 'r') as file: # open the file
2+
lines = file.read().split('\n') #when encounter a new line character, store into lines variable
3+
4+
header = lines[0].split(',')
5+
6+
contacts_list = []
7+
8+
for line in lines:
9+
contacts_dict = {}
10+
elements = line.split(',')
11+
for i in range(len(header)):
12+
contacts_dict.update({header[i]: elements[i]})
13+
contacts_list.append(contacts_dict)
14+
15+
16+
contacts_list.pop(0)
17+
print(contacts_list)
18+

0 commit comments

Comments
 (0)