Sikhumbuzo Sithole
Sikhumbuzo Sithole

Reputation: 71

Python3 i have been geting this errer [TypeError: list indices must be integers or slices, not NoneType]

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

Answers (1)

Francozen
Francozen

Reputation: 389

The error could be in the caller of getKeyDict() not supplying the second parameter key_position evaluating to None

Upvotes: 1

Related Questions