[Tutor] Pouring a list into a dictionary
Allen
aschmidt at fredericksburg.com
Mon Sep 29 18:51:21 EDT 2003
The answer to my last inquiry worked out to be this: (thanks for the
suggestions)
I have two lists (same length) and needed field ONE from list A
(headings) be the key to the value of field ONE of list B (foundData).
Iterate through these to create my dictionary.
dataDict={}
for k, v in map(None, headings, foundData):
dataDict[k]= v
Next question: How to use %s formatting (I think) to access those
key/value pairs in an sql insert statement. Here is what I need:
for k, v in map(None, headings, foundData):
dataDic[k]= v
sql = "replace into tablename %s values(%s)"
crsr.execute(sql, (dataDict.keys(),dataDict.values()))
The order does not really matter when the stuff is taken from the dict
but the key/value order obviously makes a difference when presented.
Not sure if I spelled it out right...but thought I would try.
Thanks
Allen
More information about the Tutor
mailing list