Screen Link:
https://app.dataquest.io/m/1012/functions%3A-fundamentals-practice-problems/11/checking-unique-column-values
My Code:
def check_unique_values(csv_filename, col_name):
index_num = find_col_index(csv_filename, col_name)
if index_num == -1:
return None
opened_file = open(csv_filename)
read = reader(opened_file)
csv = list(read)
rows = csv[1:]
checked = {}
for row in rows:
val = row[index_num]
if val in checked:
checked[val] += 1
if val not in checked:
checked[val] = 1
for key in checked:
if checked[key] > 1:
return False
return True
print(check_unique_values(csv_filename, col_name1))
print(check_unique_values(csv_filename, col_name2))
What I expected to happen:
I expected the correct bool outputs since I got the green to go to the next practice problem, but I got ‘True’ for all of the input samples.
'True'
'True'
'True'
No error feedback, just incorrect outputs.
After looking at the answer, the minor difference was that I assigned the column values to a variable. Did I do this correctly?