Created
August 31, 2019 02:02
-
-
Save totalys/19f1c6adee3e7adc8963ea04e5d37d21 to your computer and use it in GitHub Desktop.
Medium-Article Sequential IFs vs Dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resolveListCommands(lines): | |
response = [] | |
list = [] | |
for phase in lines: | |
line = phase.split(' ') | |
command = line[0] | |
number = 0 | |
index = 0 | |
if len(line) > 1: | |
number = int(line[1]) | |
if len(line) > 2: | |
index = int(line[2]) | |
if command == "insert": | |
list.insert(number, index) | |
elif command == "remove": | |
list.remove(number) | |
elif command == "sort": | |
list.sort() | |
elif command == "pop": | |
list.pop() | |
elif command == "reverse": | |
list.reverse() | |
elif command == "append": | |
list.append(number) | |
elif command == "print": | |
response.append(f'{list}') | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment