hackerrank Collections.deque()

来源:互联网 发布:新浪体育直播软件 编辑:程序博客网 时间:2024/05/29 12:58

题目:https://www.hackerrank.com/challenges/py-collections-deque/problem
题意:deque的基本操作
思路:基本操作
代码:

'''-*- coding: utf-8 -*-@Author  : PlayerGuan@Time    : 2017/10/14 23:12@Software: PyCharm Community Edition@File    : main.py'''from collections import dequen = int(input())dq = deque()for i in range(n):    s = input().split()    if s[0] == 'append':        dq.append(s[1])    elif s[0] == 'appendleft':        dq.appendleft(s[1])    elif s[0] == 'pop':        dq.pop()    else:        dq.popleft()print(' '.join(dq))