Reputation: 71
def getKeyDict(csv_reader, key_position):
key_dict = {}
row_counter = 0
unique_records = 0
for row in csv_reader:
row_counter += 1
if row[key_position] not in key_dict:
key_dict.update({row[key_position]: row})
unique_records += 1
# My use case requires a lot of checking for duplicates
if unique_records != row_counter:
print ("Duplicate Keys in File")
return key_dict
Upvotes: 1
Views: 45
Reputation: 389
The error could be in the caller of getKeyDict() not supplying the second parameter key_position
evaluating to None
Upvotes: 1