""" Purpose: introductory take on examining a table of values """ # this process is a good one to memorize: # import url, get file, clean file, build link, get_dataset()/get_contents() # get access to web-based data support import url # set repository folder DATASET_FOLDER = "http://www.cs.virginia.edu/~cs1112/datasets/csv/" # get name of the dataset reply = input( "Enter name of dataset: " ) file_name = reply.strip() # specify link link = DATASET_FOLDER + file_name # get dataset table = url.get_dataset( link ) # get column of interest reply = input( "Enter column index: " ) c = int( reply ) print() # accumulate cells in the column c column = [] # list accumulator starts with an empty list! for row in table : # get cell in column c of the row cell = row[ c ] # grab the element at index c from the row, that will be column c # the element in column c is the value we grab out at index c # find() doesn't work on lists, so we have to use the index and [] # list_name.index( item ) tells you the index of first instance of item # index( item ) function is backwards list_name[ index ] # add the cell to the column list column.append( cell ) # append() will always work with lists! if your append() # isn't working, you don't have a list print( "row", row, ": column", c, "cell:", cell ) # since we're looping through the list directly and not using a range() and indices, # we can't tell you what number the row is print() print( "Column", c, ":", column ) # if you want to print it as a column, loop through the column list and print() it # or look up python format string if you are really passionate about output formatting # you will only be tested on concepts that homework assignments have covered # unless someone says "will x be on the test?" # how to know if you need to use an accumulator: # context clues: compute a total, build a string/list, compute a product