classroom_grades ================ list_avg_by_row --------------- >>> from classroom_grades import list_avg_by_row >>> stgD = { ... 10: ['JBB', 0.0], ... 16: ['GWV', 7.5], ... 21: ['JJJ', 6.5], ... 27: ['AWV', 3.5], ... 31: ['MMP', 5.5], ... 35: ['BWV', 4.5], ... 42: ['SCC', 7.5], ... 49: ['BWV', 9.0], ... 55: ['FCC', 5.0], ... 72: ['ABC', 7.0], ... 81: ['GMM', 8.0], ... 92: ['MRP', 10.0], ... 99: ['ARG', 10.0], ... } >>> cl1 = [ ... [21, -1, 42, 81, -1, 10, -1], ... [16, -1, 25, -1, -1, 36, 49], ... [92, -1, 72, -1, 31, 55, 99], ... ] >>> sol = list_avg_by_row(cl1, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, 5.5, 4), (3, 7.5, 5)], [(2, 3, 25)]) >>> cl2 = [ ... [21, -1, 42, 81, -1, 10, -1], ... [16, -1, 72, -1, -1, 35, 49], ... [92, -1, 27, -1, 31, 55, 99], ... ] >>> sol = list_avg_by_row(cl2, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, 5.5, 4), (2, 7.0, 4), (3, 6.8, 5)], []) >>> cl3 = [ ... [-1, -1, -1, -1, -1, -1, -1], ... [-1, -1, -1, -1, -1, -1, -1], ... [-1, -1, -1, -1, -1, -1, -1], ... ] >>> sol = list_avg_by_row(cl3, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, -1.0, 0), (2, -1.0, 0), (3, -1.0, 0)], []) >>> cl4 = [ ... [21, -1, 42, 81, -1, 10, -1], ... [15, -1, 22, -1, -1, 31, 49], ... [92, 16, 72, 27, 35, 55, 99], ... ] >>> sol = list_avg_by_row(cl4, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, 5.5, 4), (3, 6.8, 7)], [(2, 1, 15)]) >>> cl5 = [ ... [21, 42, 81, -1, 10, -1], ... [16, 22, -1, -1, 31, 49], ... [92, 72, 27, 35, 55, 99], ... ] >>> sol = list_avg_by_row(cl5, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, 5.5, 4), (3, 6.7, 6)], [(2, 2, 22)]) >>> cl6 = [ ... [21, -1, 42, 81, -1, 10, -1], ... [16, -1, 22, -1, -1, 31, 49], ... [92, 81, 72, 27, 35, 55, 99], ... ] >>> sol = list_avg_by_row(cl6, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, 5.5, 4), (3, 6.9, 7)], [(2, 3, 22)]) >>> cl7 = [ ... [-1, -1, -1, -1, -1, -1, -1], ... [16, -1, 22, -1, -1, 31, 49], ... [92, 81, 72, 27, 35, 55, 99], ... ] >>> sol = list_avg_by_row(cl7, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, -1.0, 0), (3, 6.9, 7)], [(2, 3, 22)]) >>> cl8 = [ ... [-1, 21, 42, 81, -1, 10, -1], ... [-1, 16, 22, -1, -1, 31, -1], ... [-1, 92, 81, 72, 27, 35, -1], ... ] >>> sol = list_avg_by_row(cl8, stgD) >>> sol # doctesttag: +TAG=1_list_avg_by_row ([(1, 5.5, 4), (3, 6.6, 5)], [(2, 3, 22)]) language_dictionary =================== invert_lang_dict ---------------- >>> from language_dictionary import invert_lang_dict >>> eng_catD = { ... 'blnc': ['equilibri', 'romanent', 'saldo'], ... 'swing': ['grnxr', 'gronxador', 'balencejar'], ... 'residue': ['residu', 'saldo'], ... 'rock': ['roca', 'pedra', 'roc', 'balencejar'], ... 'stone': ['pedra',], ... } >>> d = invert_lang_dict(eng_catD) >>> solD = { ... 'equilibri': ['blnc'], ... 'romanent': ['blnc'], ... 'saldo': ['blnc', 'residue'], ... 'grnxr': ['swing'], ... 'gronxador': ['swing'], ... 'balencejar': ['rock', 'swing'], ... 'residu': ['residue'], ... 'roca': ['rock'], ... 'pedra': ['rock', 'stone'], 'roc': ['rock'] ... } >>> if d == solD: # doctesttag: +TAG=2_language_dictionary-1_invert_lang_dict ... True ... else: ... print(d) True >>> eng_catD = { ... 'w1': ['mot1', 'mot2', 'mot3'], ... 'w2': ['mot1', 'mot2', 'mot3', 'mot4'], ... 'w3': ['mot0', 'mot1', 'mot2', 'mot3'], ... } >>> d = invert_lang_dict(eng_catD) >>> solD = {'mot1': ['w1', 'w2', 'w3'], 'mot2': ['w1', 'w2', 'w3'], 'mot3': ['w1', 'w2', 'w3'], 'mot4': ['w2'], 'mot0': ['w3']} >>> if d == solD: # doctesttag: +TAG=2_language_dictionary-1_invert_lang_dict ... True ... else: ... print(d) True >>> eng_catD = { ... 'w1': ['mot1', 'mot2', 'mot3'], ... 'w2': ['mot0', 'mot1', 'mot2', 'mot3', 'mot4'], ... } >>> d = invert_lang_dict(eng_catD) >>> solD = {'mot1': ['w1', 'w2'], 'mot2': ['w1', 'w2'], 'mot3': ['w1', 'w2'], 'mot4': ['w2'], 'mot0': ['w2']} >>> if d == solD: # doctesttag: +TAG=2_language_dictionary-1_invert_lang_dict ... True ... else: ... print(d) True >>> eng_catD = { ... 'w2': ['mot0', 'mot1', 'mot2', 'mot3', 'mot4'], ... } >>> d = invert_lang_dict(eng_catD) >>> solD = {'mot1': ['w2'], 'mot2': ['w2'], 'mot3': ['w2'], 'mot0': ['w2'], 'mot4': ['w2']} >>> if d == solD: # doctesttag: +TAG=2_language_dictionary-1_invert_lang_dict ... True ... else: ... print(d) True invert_lang_dict_plus --------------------- >>> from language_dictionary import invert_lang_dict_plus >>> eng_catD1 = { ... 'blnc': ['equilibri', 'romanent', 'saldo'], ... 'swing': ['grnxr', 'gronxador', 'balencejar'], ... 'residue': ['residu', 'saldo'], ... 'rock': ['roca', 'pedra', 'roc', 'balencejar'], ... 'stone': ['pedra',]} >>> d = invert_lang_dict_plus(eng_catD1) >>> solD = {'e': {'equilibri': ['blnc']}, 'r': {'romanent': ['blnc'], 'residu': ['residue'], 'roca': ['rock'], 'roc': ['rock']}, 's': {'saldo': ['blnc', 'residue']}, 'g': {'grnxr': ['swing'], 'gronxador': ['swing']}, 'b': {'balencejar': ['rock', 'swing']}, 'p': {'pedra': ['rock', 'stone']}} >>> d == solD # doctesttag: +TAG=2_language_dictionary-2_invert_lang_dict_plus True >>> eng_catD2 = { ... 'blnc': ['equilibri', 'romanent', 'saldo'], ... 'aswing': ['grnxr', 'gronxador', 'balencejar'], ... 'bresidue': ['residu', 'saldo'], ... 'arock': ['roca', 'pedra', 'roc', 'balencejar'], ... 'bstone': ['pedra',]} >>> d = invert_lang_dict_plus(eng_catD2) >>> solD = {'e': {'equilibri': ['blnc']}, 'r': {'romanent': ['blnc'], 'residu': ['bresidue'], 'roca': ['arock'], 'roc': ['arock']}, 's': {'saldo': ['blnc', 'bresidue']}, 'g': {'grnxr': ['aswing'], 'gronxador': ['aswing']}, 'b': {'balencejar': ['arock', 'aswing']}, 'p': {'pedra': ['arock', 'bstone']}} >>> d == solD # doctesttag: +TAG=2_language_dictionary-2_invert_lang_dict_plus True >>> eng_catD3 = { ... 'blnc': ['equilibri', 'romanent', 'esaldo'], ... 'swing': ['rgrnxr', 'rgronxador', 'ebalencejar'], ... 'residue': ['residu', 'esaldo'], ... 'rock': ['roca', 'epedra', 'roc', 'ebalencejar'], ... 'stone': ['epedra',]} >>> d = invert_lang_dict_plus(eng_catD3) >>> solD = {'e': {'equilibri': ['blnc'], 'esaldo': ['blnc', 'residue'], 'ebalencejar': ['rock', 'swing'], 'epedra': ['rock', 'stone']}, 'r': {'romanent': ['blnc'], 'rgrnxr': ['swing'], 'rgronxador': ['swing'], 'residu': ['residue'], 'roca': ['rock'], 'roc': ['rock']}} >>> d == solD # doctesttag: +TAG=2_language_dictionary-2_invert_lang_dict_plus True >>> eng_catD4 = { ... 'w3': ['mot0', 'mot1', 'mot2', 'mot3'], ... 'w2': ['mot1', 'mot2', 'mot3', 'mot4'], ... 'w1': ['mot1', 'mot2', 'mot3']} >>> d = invert_lang_dict_plus(eng_catD4) >>> solD = {'m': {'mot1': ['w1', 'w2', 'w3'], 'mot2': ['w1', 'w2', 'w3'], 'mot3': ['w1', 'w2', 'w3'], 'mot4': ['w2'], 'mot0': ['w3']}} >>> d == solD # doctesttag: +TAG=2_language_dictionary-2_invert_lang_dict_plus True >>> eng_catD5 = { ... 'w3': ['lot1', 'cot2', 'mot3'], ... 'w1': ['lot1', 'cot2', 'mot4', 'mot3'], ... 'w2': ['mot4', 'lot1', 'cot2', 'mot3']} >>> d = invert_lang_dict_plus(eng_catD5) >>> solD = {'l': {'lot1': ['w1', 'w2', 'w3']}, 'c': {'cot2': ['w1', 'w2', 'w3']}, 'm': {'mot3': ['w1', 'w2', 'w3'], 'mot4': ['w1', 'w2']}} >>> d == solD # doctesttag: +TAG=2_language_dictionary-2_invert_lang_dict_plus True sininv_series ============= >>> from sininv_series import sininv_series >>> s, n = sininv_series(1, 100, 0.001) >>> round(s, 5) == 1.99678 and n == 19 # doctesttag: +TAG=3_sininv_series True >>> s, n = sininv_series(1, 20, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (1.99678, 19) >>> s, n = sininv_series(1, 19, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (1.99678, 19) >>> s, n = sininv_series(1, 10, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (1.83262, 10) >>> s, n = sininv_series(0.1, 100, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (0.17198, 7) >>> s, n = sininv_series(0.1, 6, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (0.16658, 6) >>> s, n = sininv_series(10, 100, 0.001) >>> round(s, 5) == 21.59471 and n == 47 # doctesttag: +TAG=3_sininv_series True >>> s, n = sininv_series(10, 20, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (20.07964, 20) >>> s, n = sininv_series(-1, 100, 0.001) >>> round(s,5), n # doctesttag: +TAG=3_sininv_series (-1.99678, 19) >>> s, n = sininv_series(-1, 10, 0.001) >>> round(s, 5), n # doctesttag: +TAG=3_sininv_series (-1.83262, 10) read_objects ============ >>> from objects_file import read_objects >>> l = [ ... 'NAME,ID,COLOR,UNITS,PRICE', ... 'bx,11,red,2.0', ... 'tree,23,yellow,1.60', ... 'tbl,31,blue,1.45', ... 'lmp,44,red,2.25', ... 'chr,51,blue,0.5', ... 'bed,69,blue,3.5', ... 'tree,23,yellow,1.85', ... 'spoon,77,red,3.55', ... 'tree,23,yellow,1.8', ... 'bx,11,red,2.5', ... 'chr,51,blue,0.75', ... 'tbl,31,blue,1.05', ... 'chr,51,blue,0.25', ... 'bed,69,blue,4.0', ... ] >>> with open('obj.csv', 'w') as f: ... for line in l: ... n = f.write(line+'\n') >>> solD = { ... ('bx', 11): ['red', 2, 2.25], ... ('tree', 23): ['yellow', 3, 1.75], ... ('tbl', 31): ['blue', 2, 1.25], ... ('lmp', 44): ['red', 1, 2.25], ... ('chr', 51): ['blue', 3, 0.5], ... ('bed', 69): ['blue', 2, 3.75], ... ('spoon', 77): ['red', 1, 3.55], ... } >>> d = read_objects('obj.csv') >>> d == solD # doctesttag: +TAG=4_read_objects True >>> l = [ ... 'NAME,ID,COLOR,UNITS,PRICE', ... 'bx,11,red,2.0', ... 'chr,51,blue,1.60', ... 'chr,51,blue,0.5', ... 'bx,11,red,3.5', ... 'tree,23,yellow,1.85', ... 'tree,23,yellow,1.8', ... 'bx,11,red,2.5', ... 'chr,51,blue,0.75', ... 'chr,51,blue,0.25', ... 'bx,11,red,4.0', ... ] >>> with open('obj.csv', 'w') as f: ... for line in l: ... n = f.write(line+'\n') >>> solD = {('bx', 11): ['red', 4, 3.0], ('chr', 51): ['blue', 4, 0.78], ('tree', 23): ['yellow', 2, 1.83]} >>> d = read_objects('obj.csv') >>> d == solD # doctesttag: +TAG=4_read_objects True >>> l = [ ... 'NAME,ID,COLOR,UNITS,PRICE', ... 'bx,11,red,2.0', ... 'bx,51,red,1.60', ... 'bx,51,red,0.5', ... 'bx,11,red,3.5', ... 'bx,23,red,1.85', ... 'bx,23,red,1.8', ... 'bx,11,red,2.5', ... 'bx,51,red,0.75', ... 'bx,51,red,0.25', ... 'bx,11,red,4.0', ... ] >>> with open('obj.csv', 'w') as f: ... for line in l: ... n = f.write(line+'\n') >>> solD = {('bx', 11): ['red', 4, 3.0], ('bx', 51): ['red', 4, 0.78], ('bx', 23): ['red', 2, 1.83]} >>> d = read_objects('obj.csv') >>> d == solD # doctesttag: +TAG=4_read_objects True >>> l = [ ... 'NAME,ID,COLOR,UNITS,PRICE', ... 'bx,11,red,2.0', ... 'bx,11,red,1.60', ... 'bx,11,red,0.5', ... 'bx,11,red,3.5', ... 'bx,11,red,1.85', ... 'bx,11,red,1.8', ... 'bx,11,red,2.5', ... 'bx,11,red,0.75', ... 'bx,11,red,0.25', ... 'bx,11,red,4.0', ... ] >>> with open('obj.csv', 'w') as f: ... for line in l: ... n = f.write(line+'\n') >>> solD = {('bx', 11): ['red', 10, 1.88]} >>> d = read_objects('obj.csv') >>> d == solD # doctesttag: +TAG=4_read_objects True objects ======= list_objects ------------ >>> from objects import list_objects >>> objD = { ... ('box', 11): ['red', 2, 2.25], ... ('tree', 23): ['yellow', 3, 1.75], ... ('table', 31): ['blue', 2, 1.25], ... ('lamp', 44): ['red', 1, 2.25], ... ('chair', 51): ['blue', 3, 0.5], ... ('bed', 69): ['blue', 2, 3.75], ... ('spoon', 77): ['red', 1, 3.55], ... } >>> l = list_objects(objD) >>> solL = [ ... ('box', 11, 'red', 2, 2.25), ... ('tree', 23, 'yellow', 3, 1.75), ... ('table', 31, 'blue', 2, 1.25), ... ('lamp', 44, 'red', 1, 2.25), ... ('chair', 51, 'blue', 3, 0.5), ... ('bed', 69, 'blue', 2, 3.75), ... ('spoon', 77, 'red', 1, 3.55), ... ] >>> if l == solL: # doctesttag: +TAG=5_objects-1_list_objects ... True ... else: ... print(l) True >>> d = {('box', 11): ['red', 4, 3.0], ('chair', 51): ['yellow', 4, 0.78], ('tree', 23): ['yellow', 2, 1.83]} >>> list_objects(d) # doctesttag: +TAG=5_objects-1_list_objects [('box', 11, 'red', 4, 3.0), ('chair', 51, 'yellow', 4, 0.78), ('tree', 23, 'yellow', 2, 1.83)] >>> d = {('obj', 1): ('red', 2, 2.25), ('obj', 2): ('yellow', 3, 1.75), ('obj', 3): ('blue', 2, 4.25), ('obj', 4): ('red', 1, 2.25), ('obj', 5): ('blue', 3, 0.5), ('obj', 6): ('blue', 2, 3.75), ('obj', 7): ('red', 1, 1.55)} >>> list_objects(d) # doctesttag: +TAG=5_objects-1_list_objects [('obj', 1, 'red', 2, 2.25), ('obj', 2, 'yellow', 3, 1.75), ('obj', 3, 'blue', 2, 4.25), ('obj', 4, 'red', 1, 2.25), ('obj', 5, 'blue', 3, 0.5), ('obj', 6, 'blue', 2, 3.75), ('obj', 7, 'red', 1, 1.55)] >>> list_objects({}) # doctesttag: +TAG=5_objects-1_list_objects [] sort_objects ------------ >>> from objects import sort_objects >>> objL = [ ... ('box', 11, 'rd', 2, 2.25), ... ('tree', 23, 'yll', 3, 1.75), ... ('table', 31, 'blu', 2, 1.25), ... ('lamp', 44, 'rd', 1, 2.25), ... ('chair', 51, 'blu', 3, 0.5), ... ('bed', 69, 'blu', 2, 3.75), ... ('spoon', 77, 'rd', 1, 3.55), ... ] >>> copy = objL.copy() >>> solL = [ ... ('bed', 69, 'blu', 2, 3.75), ... ('table', 31, 'blu', 2, 1.25), ... ('chair', 51, 'blu', 3, 0.5), ... ('spoon', 77, 'rd', 1, 3.55), ... ('lamp', 44, 'rd', 1, 2.25), ... ('box', 11, 'rd', 2, 2.25), ... ('tree', 23, 'yll', 3, 1.75) ... ] >>> l = sort_objects(objL) >>> l == solL and objL == copy # doctesttag: +TAG=5_objects-2_sort_objects True >>> objL = [('box', 11, 'rd', 2, 2.25), ('tree', 23, 'rd', 3, 1.75), ('table', 31, 'rd', 2, 1.25), ('lamp', 44, 'rd', 1, 2.25), ('chair', 51, 'rd', 3, 0.5), ('bed', 69, 'rd', 2, 3.75), ('spoon', 77, 'rd', 1, 3.55)] >>> copy = objL.copy() >>> solL = [('spoon', 77, 'rd', 1, 3.55), ('lamp', 44, 'rd', 1, 2.25), ('bed', 69, 'rd', 2, 3.75), ('box', 11, 'rd', 2, 2.25), ('table', 31, 'rd', 2, 1.25), ('tree', 23, 'rd', 3, 1.75), ('chair', 51, 'rd', 3, 0.5)] >>> l = sort_objects(objL) >>> l == solL and objL == copy # doctesttag: +TAG=5_objects-2_sort_objects True >>> objL = [('box', 11, 'rd', 2, 2.25), ('tree', 23, 'rd', 2, 1.75), ('table', 31, 'rd', 2, 1.25), ('lamp', 44, 'rd', 2, 2.25), ('chair', 51, 'rd', 2, 0.5), ('bed', 69, 'rd', 2, 3.75), ('spoon', 77, 'rd', 2, 3.55)] >>> copy = objL.copy() >>> solL = [('bed', 69, 'rd', 2, 3.75), ('spoon', 77, 'rd', 2, 3.55), ('box', 11, 'rd', 2, 2.25), ('lamp', 44, 'rd', 2, 2.25), ('tree', 23, 'rd', 2, 1.75), ('table', 31, 'rd', 2, 1.25), ('chair', 51, 'rd', 2, 0.5)] >>> l = sort_objects(objL) >>> l == solL and objL == copy # doctesttag: +TAG=5_objects-2_sort_objects True >>> objL = [('box', 11, 'rd', 2, 2.25), ('tree', 23, 'rd', 2, 2.25), ('table', 31, 'rd', 2, 2.25), ('lamp', 44, 'rd', 2, 2.25), ('chair', 51, 'rd', 2, 2.25), ('bed', 69, 'rd', 2, 2.25), ('spoon', 77, 'rd', 2, 2.25)] >>> copy = objL.copy() >>> solL = [('box', 11, 'rd', 2, 2.25), ('tree', 23, 'rd', 2, 2.25), ('table', 31, 'rd', 2, 2.25), ('lamp', 44, 'rd', 2, 2.25), ('chair', 51, 'rd', 2, 2.25), ('bed', 69, 'rd', 2, 2.25), ('spoon', 77, 'rd', 2, 2.25)] >>> l = sort_objects(objL) >>> l == solL and objL == copy # doctesttag: +TAG=5_objects-2_sort_objects True