0
我想在Python中为CSV文件添加一个新的键:值。密钥的新值来自表中现有密钥的值。Python添加到词典.csv格式
def addKey(allData):
allData = []
for i in range (0, len(allData)):
while i > 0 and allData[i] == allData[i+1]:
newKey = {}
newKeyVal = int(allData['key1']*100 + allData['key2'])
allData = dict(allData, newKey = newKeyVal)
return allData
有什么建议吗?我有一种感觉,这个代码从一开始就是错误的。
谢谢,到目前为止我做了这些更改,但是,现在我得到“IndexError:list index out of range”for this line:while i> 0 and allData [i] == allData [i + 1] : – user1322596 2012-04-09 20:17:44