def realign(self, case_dict): ''' Take the case dictionary, which has the string form of the word Phonemicize and realign the word such that roots line up ''' replaced = map(functions.replace, case_dict.values()) syllabified = map(functions.syllabify, replaced) CtoO = map(functions.codaToOnset, syllabified) dashes = map(functions.addDashes, CtoO) final_forms = [] # List of lengths and max lengths = [] len_list = map(len, dashes) max_len = max(len_list) # Check if all elements equal. If they are, build one forward len_equal = functions.checkEqual(len_list) for form in dashes: # Determine form length form_len = len(form) # Length difference tells us how many to build forward len_diff = max_len - form_len # Difference from 6 tells us how many to build back diff_from_six = 6 - max_len # Now build if len_equal: final_form = ['-' * 8] * (diff_from_six - 1) + form + ['-' * 8] else: final_form = ['-' * 8] * diff_from_six + form + ['-' * 8 ] * len_diff # Sanity check if len(final_form) != 6: print 'The word is misaligned' raise SystemExit else: final_forms.append(final_form) return dict(zip(case_dict.keys(), final_forms))
def realign(self, case_dict): ''' Take the case dictionary, which has the string form of the word Phonemicize and realign the word such that roots line up ''' replaced = map(functions.replace, case_dict.values()) syllabified = map(functions.syllabify, replaced) CtoO = map(functions.codaToOnset, syllabified) dashes = map(functions.addDashes, CtoO) final_forms = [] # List of lengths and max lengths = [] len_list = map(len, dashes) max_len = max(len_list) # Check if all elements equal. If they are, build one forward len_equal = functions.checkEqual(len_list) for form in dashes: # Determine form length form_len = len(form) # Length difference tells us how many to build forward len_diff = max_len - form_len # Difference from 6 tells us how many to build back diff_from_six = 6 - max_len # Now build if len_equal: final_form = ['-'*8]*(diff_from_six-1) + form + ['-'*8] else: final_form = ['-'*8]*diff_from_six + form + ['-'*8]*len_diff # Sanity check if len(final_form) != 6: print 'The word is misaligned' raise SystemExit else: final_forms.append(final_form) return dict(zip(case_dict.keys(), final_forms))
"""Python Homework #3 - If Statements""" import functions # Print details print("Check equal numbers 9, 8, 8") print(functions.checkEqual(9,"8",8)) print("Check equal numbers 101, 101, 450") print(functions.checkEqual(101, 101, 450)) print("Check equal numbers 10, 1.01, 10") print(functions.checkEqual(10, 1.01, 10)) print("Check equal numbers -1.234 1.234, -8.3") print(functions.checkEqual(-1.234, 1.234, -8.3)) print("Check equal numbers 5.3, -54, -5.3") print(functions.checkEqual(5.3, -54, -5.3)) print("Check equal numbers -1.1, -5.3, -1.1") print(functions.checkEqual(-1.1, -5.3, -1.1))