for d in data will give you list objects
Example ...
'''
contents of file or.csv:
1, 23.27, 23.21, 83.22
2, 34.25, 65.31, 34.75
'''
import csv
Or = csv.reader(open('Or.csv'))
for d in Or:
print(d, type(d))
''' result ...
['1', ' 23.27', ' 23.21', ' 83.22'], <type 'list'>
['2', ' 34.25', ' 65.31', ' 34.75'], <type 'list'>
'''
You have to do something like this ...
'''
contents of file or.csv:
1, 23.27, 23.21, 83.22
2, 34.25, 65.31, 34.75
'''
import csv
import collections as co
def make_dict(data):
return co.OrderedDict((d[0], d) for d in data if d)
Or = csv.reader(open('Or.csv'))
updated = make_dict(Or)
print(updated)
''' result ...
OrderedDict([('1', ['1', ' 23.27', ' 23.21', ' 83.22']), ('2', ['2', ' 34.25', ' 65.31', ' 34.75'])])
'''
vegaseat
DaniWeb's Hypocrite
6,478 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,612
Skill Endorsements: 37
Question Answered as of 5 Months Ago by
vegaseat
and
radhakrishna.p