python 2.7 - Dictionary Key Error -


i trying construct dictionary values csv file.say 10 columns there , want set first column key , remaining values. if setting loop dictionary has have 1 value. kindly suggest me way.

import csv import numpy aname = {} #loading file in numpy result=numpy.array(list(csv.reader(open('somefile',"rb"),delimiter=','))).astype('string') #devolop dict\ r = {aname[rows[0]]: rows[1:] rows in result} print r[0] 

error follows.

r = {aname[rows[0]]: rows[1:] rows in result}
keyerror: '2a9ac84c-3315-5576-4dfd-8bc34072360d|11937055'

i'm not entirely sure mean here, help:

>>> result = [[1, 'a', 'b'], [2, 'c', 'd']] >>> dict([(row[0], row[1:]) row in result]) {1: ['a', 'b'], 2: ['c', 'd']} 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -