I have problems with the following Code. I'm trying to read datas from a CSV file to create a nested dictonary. When I run it the first time it does exactly what I intent but when I run it twice it changes the order of the output. Does anyone have an idea why this is hapening? I'm using Python 3.4.
import csv
delimiter = ';'
result = {}
with open("F:\\Python Projects\\Database.csv", 'r') as data_file:
data = csv.reader(data_file, delimiter=delimiter)
headers = next(data)[1:]
for row in data:
temp_dict = {}
name = row[0]
values = []
for x in row[1:]:
values.append(x)
for i in range(len(values)):
temp_dict[headers[i]] = values[i]
result[name] = temp_dict
print(result)
My input looks like this:
and the result is this:
Column 1 shows a diffrent order when I run the code twice.