Person Node Value
Bob A 2
Bob A 3
Bob A 4
Bob B 2
Bob B 3
Jill A 1
Jill B 2
I am attempting to get the following into a data structure similar to this
{ 'Bob': { 'A':[2,3,4],'B':[2,3], :'Jill':{'A':[1], 'B':[2]}
I know this might not be the best approach, but what I am trying to do with my data structure is the following:
- Dictionary whose key is a value and check if it a value.
- Value of dictionary is another dictionary and need to check if key is already in the value.
- Value of the second dictionary is a list which needs to be appended to if the list exists like in Bob's case.
I have tried numerous approaches, but right now, my code is looking like this.
names = {}
with open('impacts.csv', 'rb') as csvfile:
namesreaders = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in namesreaders:
person, letter, value = row[0], row[1], row[2]
if person not in names:
names[person] = { letter: value}
else:
print 'Lost a bit'
### Lost here
print names