| n | def morse_encode(input_string, di, dah, dit, end): | n | def to_morse(input_string, di, dah, dit, end): | 
             |     result = [] |  |     result = [] | 
             |     for i in range(len(input_string)): |  |     for i in range(len(input_string)): | 
             |         if input_string[i] == '-': |  |         if input_string[i] == '-': | 
             |             result.extend(dah) |  |             result.extend(dah) | 
             |             result.append(' ') |  |             result.append(' ') | 
             |         elif input_string[i] == '+' and i == len(input_string) - 1: |  |         elif input_string[i] == '+' and i == len(input_string) - 1: | 
             |             result.extend(dit) |  |             result.extend(dit) | 
             |             result.append(' ') |  |             result.append(' ') | 
             |         elif input_string[i] == '+' and i < len(input_string) - 1 and (i |  |         elif input_string[i] == '+' and i < len(input_string) - 1 and (i | 
             | nput_string[i + 1] == '~'): |  | nput_string[i + 1] == '~'): | 
             |             result.extend(dit) |  |             result.extend(dit) | 
             |             result.append(' ') |  |             result.append(' ') | 
             |         elif input_string[i] == '+': |  |         elif input_string[i] == '+': | 
             |             result.extend(di) |  |             result.extend(di) | 
             |             result.append(' ') |  |             result.append(' ') | 
             |         elif input_string[i] == '~' and i != len(input_string) - 1: |  |         elif input_string[i] == '~' and i != len(input_string) - 1: | 
             |             if result: |  |             if result: | 
             |                 result.pop() |  |                 result.pop() | 
             |             result.append(',') |  |             result.append(',') | 
             |             result.append(' ') |  |             result.append(' ') | 
             |     if result: |  |     if result: | 
             |         result.pop() |  |         result.pop() | 
             |     result.append(end) |  |     result.append(end) | 
             |     return ''.join(result) |  |     return ''.join(result) | 
             |  |  |  | 
            | n | def morse_encode_alternate(input_string, di, dah, dit, end): | n | def to_morse2(input_string, di, dah, dit, end): | 
             |     result = [] |  |     result = [] | 
             |     for i in range(len(input_string)): |  |     for i in range(len(input_string)): | 
             |         if input_string[i] == '-': |  |         if input_string[i] == '-': | 
             |             result.extend(dah) |  |             result.extend(dah) | 
             |         elif input_string[i] == '+' and i == len(input_string) - 1: |  |         elif input_string[i] == '+' and i == len(input_string) - 1: | 
             |             result.extend(dit) |  |             result.extend(dit) | 
             |         elif input_string[i] == '+' and i < len(input_string) - 1 and (i |  |         elif input_string[i] == '+' and i < len(input_string) - 1 and (i | 
             | nput_string[i + 1] == '~'): |  | nput_string[i + 1] == '~'): | 
             |             result.extend(dit) |  |             result.extend(dit) | 
             |         elif input_string[i] == '+': |  |         elif input_string[i] == '+': | 
             |             result.extend(di) |  |             result.extend(di) | 
             |         elif input_string[i] == '~' and i != len(input_string) - 1: |  |         elif input_string[i] == '~' and i != len(input_string) - 1: | 
             |             result.append(' ') |  |             result.append(' ') | 
             |     result.append(end) |  |     result.append(end) | 
             |     return ''.join(result) |  |     return ''.join(result) | 
             |  |  |  | 
             | class morse: |  | class morse: | 
             |  |  |  | 
             |     def __init__(self, input_string=None): |  |     def __init__(self, input_string=None): | 
             |         self.dah = 'dah' |  |         self.dah = 'dah' | 
             |         self.dit = 'dit' |  |         self.dit = 'dit' | 
             |         self.di = 'di' |  |         self.di = 'di' | 
             |         self.code = '' |  |         self.code = '' | 
             |         self.end = '.' |  |         self.end = '.' | 
             |         self.flag = 0 |  |         self.flag = 0 | 
             |         if input_string and ' ' not in input_string: |  |         if input_string and ' ' not in input_string: | 
             |             self.flag = 1 |  |             self.flag = 1 | 
             |             if len(input_string) == 2: |  |             if len(input_string) == 2: | 
             |                 self.di, self.dah = (input_string[0], input_string[1]) |  |                 self.di, self.dah = (input_string[0], input_string[1]) | 
             |                 self.dit = self.di |  |                 self.dit = self.di | 
             |                 self.end = '' |  |                 self.end = '' | 
             |             elif len(input_string) == 3: |  |             elif len(input_string) == 3: | 
             |                 self.di, self.dit, self.dah = (input_string[0], input_st |  |                 self.di, self.dit, self.dah = (input_string[0], input_st | 
             | ring[1], input_string[2]) |  | ring[1], input_string[2]) | 
             |                 self.end = '' |  |                 self.end = '' | 
             |             else: |  |             else: | 
             |                 self.di, self.dit, self.dah, self.end = (input_string[0] |  |                 self.di, self.dit, self.dah, self.end = (input_string[0] | 
             | , input_string[1], input_string[2], input_string[3]) |  | , input_string[1], input_string[2], input_string[3]) | 
             |         elif input_string: |  |         elif input_string: | 
             |             if input_string[-1] == ' ': |  |             if input_string[-1] == ' ': | 
             |                 self.end = '' |  |                 self.end = '' | 
             |             elements = input_string.split() |  |             elements = input_string.split() | 
             |             if len(elements) == 2: |  |             if len(elements) == 2: | 
             |                 self.di, self.dah = elements |  |                 self.di, self.dah = elements | 
             |                 self.dit = self.di |  |                 self.dit = self.di | 
             |             elif len(elements) == 3: |  |             elif len(elements) == 3: | 
             |                 self.di, self.dit, self.dah = elements |  |                 self.di, self.dit, self.dah = elements | 
             |             else: |  |             else: | 
             |                 self.di, self.dit, self.dah, self.end = elements |  |                 self.di, self.dit, self.dah, self.end = elements | 
             |  |  |  | 
             |     def __pos__(self): |  |     def __pos__(self): | 
             |         self.code += '+' |  |         self.code += '+' | 
             |         return self |  |         return self | 
             |  |  |  | 
             |     def __neg__(self): |  |     def __neg__(self): | 
             |         self.code += '-' |  |         self.code += '-' | 
             |         return self |  |         return self | 
             |  |  |  | 
             |     def __invert__(self): |  |     def __invert__(self): | 
             |         self.code += '~' |  |         self.code += '~' | 
             |         return self |  |         return self | 
             |  |  |  | 
             |     def __repr__(self): |  |     def __repr__(self): | 
             |         if not self.code: |  |         if not self.code: | 
             |             return '.' |  |             return '.' | 
             |         elif self.flag == 0: |  |         elif self.flag == 0: | 
            | n |             return morse_encode(self.code[::-1], self.di, self.dah, self | n |             return to_morse(self.code[::-1], self.di, self.dah, self.dit | 
             | .dit, self.end) |  | , self.end) | 
             |         else: |  |         else: | 
            | t |             return morse_encode_alternate(self.code[::-1], self.di, self | t |             return to_morse2(self.code[::-1], self.di, self.dah, self.di | 
             | .dah, self.dit, self.end) |  | t, self.end) |