Difference between revisions of "Spreadsheet To Dictionaries Assignment"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
Follows [[Spreadsheet_Assignment|Spreadsheet]] and [[Chained_Dictionary_Assignment|Chained Dictionaries]] exercises. | Follows [[Spreadsheet_Assignment|Spreadsheet]] and [[Chained_Dictionary_Assignment|Chained Dictionaries]] exercises. | ||
+ | =Inspiration= | ||
+ | The aggressively helpful Ruby libraries which support CSV parsing to hashes with headers as keys. | ||
=Code To Implement= | =Code To Implement= | ||
==structure SpreadsheetToDictionaries== | ==structure SpreadsheetToDictionaries== |
Revision as of 03:33, 19 October 2022
Follows Spreadsheet and Chained Dictionaries exercises.
Contents
Inspiration
The aggressively helpful Ruby libraries which support CSV parsing to hashes with headers as keys.
Code To Implement
structure SpreadsheetToDictionaries
to_dictionaries_using_headers_as_keys
fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list = raise NotYetImplemented
Given this spreadsheet:
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
to_dictionaries_using_headers_as_keys
should return a list with 3 single list dictionaries, one for each non-header row. The dictionaries would be filled with entries for each column, using the cell in the header of the column as the key and the cell in the particular row of the column as the value.
[ { TEXT("Name") => TEXT("Bobby Orr"), TEXT("Uniform Number") => INTEGER(4), TEXT("Birth Year") => INTEGER(1948), TEXT("Games Played") => INTEGER(657), TEXT("Goals") => INTEGER(270), TEXT("Assists") => INTEGER(645) }, { TEXT("Name") => TEXT("Wayne Gretzky"), TEXT("Uniform Number") => INTEGER(99), TEXT("Birth Year") => INTEGER(1961), INTEGER("Games Played") => INTEGER(1487), TEXT("Goals") => INTEGER(894), TEXT("Assists") => INTEGER(1963) }, { TEXT("Name") => TEXT("Mario Lemieux"), TEXT("Uniform Number") => INTEGER(66), TEXT("Birth Year") => INTEGER(1965), INTEGER("Games Played") => INTEGER(915), TEXT("Goals") => INTEGER(690), TEXT("Assists") => INTEGER(1033) } ]
NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising Empty seems like a reasonable thing to do.
Testing
source folder: | src/test/sml/spreadsheet_to_dictionaries |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_spreadsheet_to_dictionaries_testing.sml |
how to run with CM.make verbosity on: | sml run_spreadsheet_to_dictionaries_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.