''' Purpose: for a user-specified dataset, dataset a user-specified column label, label a column value, key counts the number of rows whose column values equals key ''' # get a hold of helpful web functions import url # specify base web folder for datasets CSV_REPOSITORY = 'http://www.cs.virginia.edu/~cs1112/datasets/csv/' # get dataset of interest reply = input( 'Enter the name of a data set: ' ) name = reply.strip() link = CSV_REPOSITORY + name dataset = url.get_dataset( link ) # get label for the column of interest reply = input( 'Enter column label for the data set: ' ) label = reply.strip() # get key value for column of interest reply = input( 'Enter the key: ' ) key = reply.strip() print() # identify header and data from the dataset header = dataset[ 0 ] table = dataset[ 1 : ] # get the index i of the dataset column of interest i = header.index(label) #finds which entry has the label we want #print( i ) # get from dataset, a list of values for the column of interest column_values = [] #accumulation requires an accumulator for row in table: cell_of_interest = row[i] column_values.append(cell_of_interest) #for each row, we will grab the value at the corresponding location #the spot we're grabbing corresponds to the label asked for earlier #we then append that value to our accumulator # count from that list of values, the number of values equalling the key number = column_values.count(key) # count the number of times our key occurs # print the total print(number)