파이썬 독학기 [Letter Queue] - Empire of Code
Letter QueueIn computer science, a queue is a particular kind of data type in which the entities in the collection are kept in order and the principal operations on the collection are the addition of entities to the rear terminal position (enqueue or push), and removal of entities from the front terminal position (dequeue or pop).
from string import ascii_uppercase
alpha_list = list(ascii_uppercase) #알파벳 리스트 치기 귀찮아서 ascii로 불러 왔습니다. 근데 이게 더 귀찮네요.
def letter_queue(commands):
result = ""
for i in range(len(commands)):
for j in alpha_list:
if commands[i] == "PUSH " + j:
result += j
if commands[i] == "POP":
result = result[1:]
return result
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert letter_queue(("PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T")) == "DOT", "dot example"
assert letter_queue(("POP", "POP")) == "", "Pop, Pop, empty"
assert letter_queue(("PUSH H", "PUSH I")) == "HI", "Hi!"
assert letter_queue(()) == "", "Nothing"
print("All done? Earn rewards by using the 'Check' button!")
'IT 어떻게든 혼자 해결해보자 > IT 파이썬 독학 입문기' 카테고리의 다른 글
"이동평균선(Moving Avergae Line : MA) 분석" 파이썬으로 배우는 알고리즘 투자 스터디 자료 (0) | 2018.05.09 |
---|---|
"Pandas DataFrame" 파이썬으로 배우는 알고리즘 트레이딩 스터디 자료 (0) | 2018.05.08 |
"DataFrame 칼럼(열), 로우(행) 선택" 파이썬으로 배우는 알고리즘 트레이딩 스터디 자료 (0) | 2018.05.07 |
"pandas_datareader 패키지 사용" 파이썬으로 배우는 알고리즘 스터디자료 (0) | 2018.05.07 |
"Python Console" 파이썬으로 배우는 알고리즘 트레이딩 스터디 자료 (0) | 2018.05.07 |
댓글