#!/usr/local/bin/python3 # Author: Dr. Robert Heckendorn, Computer Science Department, University of Idaho, 2013 # ensemble performance # functionality of a symbol table: # 1. make symbol table # 2. length of symbol table # 3. list of keys # 4. insert a new item by key (no duplicates) # 5. retrieve value based on key if not there return default # 6. remove a specific item by key # 7. sort the symbol table by the keys # 8. join one symbol table to another # 9. print sorted list of keys and values # # associative memory: LISP, Icon, Perl, Python # # implementation: a sorted list of (key, value) pairs def makesymt() : return [] def length(st) : return len(st) def keys(st) : ans = [] for pair in st : ans.append(pair[0]) return ans # Any reason to keep it ordered if you don't use it here? # assume order in increasing size # returns first element >= key or end of list def findkey(st, key) : for i in range(0, len(st)) : if st[i][0]>=key : return i return len(st) # where to put it if we can't find it # allow duplicate keys def insert(st, key, value) : ans = findkey(st, key) # print("new key:", ans, st, key, value) if ans