User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Python dictionary help Page [1]  
Ernie
All American
45943 Posts
user info
edit post

So I have a script that opens and reads a csv file. I'm trying to take what I get from the csv file, do some math, and store the updated values in a dictionary; only I can't get that last step to work.

import csv

d = {}

reader = csv.reader(open('file.csv', 'rb'))
for row in reader:
name = row[0]
date = row[1]
x = row[2]
y = row[3]
z = x + y


The dictionary I'd like to store the values in would look like:

d = {
'Jim': [
{'2008-04-19':17},
{'2008-04-17':15}
],
'Bob': [
{'2008-02-11':18},
{'2008-01-12':22}
]
}


It seems like I couldn't use d.update() because that would just overwrite whatever is already in d. And there isn't an append() function for dictionaries, which I would think would make this a lot easier. So, help me.

[Edited on April 19, 2008 at 1:06 PM. Reason : ]

4/19/2008 12:59:52 PM

Ernie
All American
45943 Posts
user info
edit post

Never mind, apparently update() does the trick.

4/19/2008 3:18:00 PM

 Message Boards » Tech Talk » Python dictionary help Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.