Difference between revisions of "Spreadsheet To Dictionaries Assignment"
Jump to navigation
Jump to search
Line 40: | Line 40: | ||
<nowiki>[ { 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) }, | <nowiki>[ { 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") => | + | { 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") => | + | { 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) } ]</nowiki> |
NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising [https://smlfamily.github.io/Basis/list.html#SIG:LIST.Empty:EXN Empty] seems like a reasonable thing to do. | NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising [https://smlfamily.github.io/Basis/list.html#SIG:LIST.Empty:EXN Empty] seems like a reasonable thing to do. |
Revision as of 03:29, 19 October 2022
Follows Spreadsheet Exercise.
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.