-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataTransformation.py
44 lines (26 loc) · 954 Bytes
/
dataTransformation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import py
import collections
user1 = ["(Name) JohnDoe", "(Age) 20", "(City) Ashtabula", "(Flags) NYN"]
user2 = ["Name:Jane Doe", "City:Kingsville, OH", "Flags:YNY"]
user3 = ["Name:Sally Jones", "Age:25", "City:Paris", "Flags:YYY"]
# build hash table structure to index key value pair from string.
# split from " " between Key and Value
#hash table to should be able to index all values
#Name -> UserName
#Age -> UserAge
#City -> UserCity
#Flags -> UserFlag
my_dict = dict()
# loop through the string array split strings in to key value pairs
for s in user1:
key, value = s.split(' ')
if key in my_dict.keys():
my_dict[key] += int(value)
continue
my_dict[key] = str(value)
# create function that print out stardard format
def print_inventory(my_dict):
for index, user in my_dict.items():
print("{}\t{}".format(index, user))
print_inventory(my_dict)
#Output records in standard output formate.