Remove redundant sharps and flats from the given note. Examples: >>> remove_redundant_accidentals('C##b') 'C#' >>> remove_redundant_accidentals('Eb##b') 'E'
(note)
| 118 | |
| 119 | |
| 120 | def remove_redundant_accidentals(note): |
| 121 | """Remove redundant sharps and flats from the given note. |
| 122 | |
| 123 | Examples: |
| 124 | >>> remove_redundant_accidentals('C##b') |
| 125 | 'C#' |
| 126 | >>> remove_redundant_accidentals('Eb##b') |
| 127 | 'E' |
| 128 | """ |
| 129 | val = 0 |
| 130 | for token in note[1:]: |
| 131 | if token == "b": |
| 132 | val -= 1 |
| 133 | elif token == "#": |
| 134 | val += 1 |
| 135 | result = note[0] |
| 136 | while val > 0: |
| 137 | result = augment(result) |
| 138 | val -= 1 |
| 139 | while val < 0: |
| 140 | result = diminish(result) |
| 141 | val += 1 |
| 142 | return result |
| 143 | |
| 144 | |
| 145 | def augment(note): |