| Total Complexity | 4 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | def letter_queue(commands): |
||
| 2 | queue = [] |
||
| 3 | for i in commands: |
||
| 4 | temp = i.split() |
||
| 5 | if temp[0].strip() == 'PUSH': |
||
| 6 | queue.append(temp[1].strip()) |
||
| 7 | elif temp[0].strip() == 'POP': |
||
| 8 | queue = queue[1:] |
||
| 9 | return ''.join(queue) |
||
| 10 | |||
| 11 | |||
| 12 | if __name__ == '__main__': |
||
| 13 | # These "asserts" using only for self-checking and not necessary for |
||
| 14 | # auto-testing |
||
| 15 | assert ( |
||
| 16 | letter_queue( |
||
| 17 | ["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"] |
||
| 18 | ) |
||
| 19 | == "DOT" |
||
| 20 | ), "dot example" |
||
| 21 | assert letter_queue(["POP", "POP"]) == "", "Pop, Pop, empty" |
||
| 22 | assert letter_queue(["PUSH H", "PUSH I"]) == "HI", "Hi!" |
||
| 23 | assert letter_queue([]) == "", "Nothing" |
||
| 24 |