Problem:


Doubly Linked List

Your task is to implement a double linked list.

Write a program which performs the following operations:

insert x: insert an element with key x into the front of the list.

delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.

deleteFirst: delete the first element from the list. 

deleteLast: delete the last element from the list. 

Input

The input is given in the following format:

n

command1 

command2 

...

commandn 

In the first line, the number of operations n is given. In the following n lines, the above mentioned operations are given in the following format:

insert x

delete x

deleteFirst 

deleteLast 

Output

Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.

Constraints

The number of operations ≤ 2,000,000

The number of delete operations ≤ 20

0 ≤ value of a key ≤ 109

The number of elements in the list does not exceed 106

For a delete, deleteFirst or deleteLast operation, there is at least one element in the list.

Sample Input 1

7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5

Sample Output 1

6 1 2

Sample Input 2

9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast

Sample Output 2

1

Template in C
-->


Sample input:
7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5


Sample output:
6 1 2

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=int(x.split()[-1])), _input))
        task_deque = deque()
        for task in task_list:
            if task.get('action')=='insertion':
                task_deque.appendleft(task.get('value'))
            else:
                task_deque.remove(task.get('value'))

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length

if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=int(x.split()[-1])), _input))
        task_deque = deque()
        for task in task_list:
            if task.get('action')=='insert':
                task_deque.appendleft(task.get('value'))
            else:
                task_deque.remove(task.get('value'))

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length

if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=int(x.split()[-1])), _input))
        task_deque = deque()
        for task in task_list:
            action = task.get('action')
            if action == 'insert':
                task_deque.appendleft(task.get('value'))
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            else:
                task_deque.remove(task.get('value'))

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=x.split()[-1]), _input))
        task_deque = deque()
        for task in task_list:
            action = task.get('action')
            if action == 'insert':
                task_deque.appendleft(task.get('value'))
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            else:
                task_deque.remove(task.get('value'))

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=x.split()[-1]), _input))
        task_deque = deque()
        for task in task_list:
            action = task.get('action')
            value = task.get('value')
            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete':
                task_deque.remove(value)

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Runtime Error

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=x.split()[-1]), _input))
        assert len(task_list) == array_length
        task_deque = deque()

        for i in range(array_length):
            task = task_list[i]
            action = task.get('action')
            value = task.get('value')
            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete':
                task_deque.remove(value)

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque

d = deque()
n = int(input())
lines = sys.stdin.readlines()
for i in range(n):
    ins = lines[i].split()
    command = ins[0]
    if command == "insert":
        d.appendleft(ins[1])
    elif command == "delete":
        d.remove(ins[1])
    elif command == "deleteFirst":
        d.popleft()
    elif command == "deleteLast":
        d.pop()

print(" ".join(d))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from collections import deque

def parse_cmd(deque,input_cmd):
	if input_cmd[0] == 'insert':
		deque.appendleft(input_cmd[1])
	elif input_cmd[0] == 'delete':
		deque.remove(input_cmd[1])
	elif input_cmd[0] == 'deleteFirst':
		deque.popleft()
	elif input_cmd[0] == 'deleteLast':
		deque.pop()
		
def main():
	que = deque()
	n = int(raw_input())
	cmd = [raw_input().split() for _ in range(n)]
	
	for i in cmd:
		parse_cmd(que,i)
	
	print " ".join(que)


#def test():

if __name__ == '__main__':
	main()
	#test()

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    dll = Doubly_Linked_List()
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            dll.insert(o[1])
        elif opcode == "delete":
            dll.delete(o[1])
        elif opcode == "deleteFirst":
            dll.deleteFirst()
        elif opcode == "deleteLast":
            dll.deleteLast()
        #print(dll.prev.data)

    return dll.get_list()
class Doubly_Linked_List:
    
    def __init__(self):
        self.next = None
        self.prev = None
        self.data = "dummy"

    def get_list(self):
        first = self
        while first.prev:
            first = first.prev
            
        target = first
        l = [target.data]
        while target.next:
            if not target.next.data == "dummy":
                l.append(target.next.data)
            target = target.next
        return l
    
    def insert(self, x):
        
        first = self
        while first.prev:
            first = first.prev

        first.prev = Doubly_Linked_List()#???????????????
        first.prev.next = first
        first.prev.data = x

    def deleteFirst(self):
        first = self

        while first.prev:
            first = first.prev

        if first.data == "dummy" :
            first.next = first.next.next
            first.next.last = first
        else:
            first.next.prev = None
        
    def deleteLast(self):
        last = self
        
        while last.next:
            last = last.next

        if last.data == "dummy":
            last.prev = last.prev.prev
            last.prev.next = last
        else:
            last.prev.next = None
        
    def delete(self, x):
        first = self
        while first.prev:
            first = first.prev

        target = first
        while not target.data == x:
            target = target.next

        if target.prev == None:
            target.next.prev = None
        elif target.next == None:
            target.prev.next = None
        else:
            target.next.prev = target.prev
            target.prev.next = target.next

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    dll = Doubly_Linked_List()
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            dll.insert(o[1])
        elif opcode == "delete":
            dll.delete(o[1])
        elif opcode == "deleteFirst":
            dll.deleteFirst()
        elif opcode == "deleteLast":
            dll.deleteLast()
        #print(dll.get_list())
    return dll.get_list()

class Doubly_Linked_List:
    
    def __init__(self):
        self.next = None
        self.prev = None
        self.data = "dummy"

    def get_list(self):
        first = self
        while first.prev:
            first = first.prev
            
        target = first
        l = [target.data]
        while target.next:
            if not target.next.data == "dummy":
                l.append(target.next.data)
            target = target.next
        return l
    
    def insert(self, x):
        
        first = self
        while first.prev:
            first = first.prev

        first.prev = Doubly_Linked_List()#???????????????
        first.prev.next = first
        first.prev.data = x

    def deleteFirst(self):
        first = self

        while first.prev:
            first = first.prev

        if first.data == "dummy" :
            first.next = first.next.next
            first.next.last = first
        else:
            first.next.prev = None
        
    def deleteLast(self):
        last = self
        
        while last.next:
            last = last.next

        if last.data == "dummy":
            last.prev = last.prev.prev
            last.prev.next = last
        else:
            last.prev.next = None
        
    def delete(self, x):
        first = self
        while first.prev:
            first = first.prev

        target = first
        while not target.data == x:
            if target.next:
                target = target.next
            else:
                return
    
        if target.prev == None:
            target.next.prev = None
        elif target.next == None:
            target.prev.next = None
        else:
            target.next.prev = target.prev
            target.prev.next = target.next

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=1000000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0]=='insert':
        q.appendleft(int(com[1]))
    elif com[0]=='delete':
        try:
            q.remove(int(com[0]))
        except ValueError:
            pass
    elif com[0]=='deleteFirst':
        q.popleft()
    elif com[0]=='deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=1000000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0]=='insert':
        q.appendleft(int(com[1]))
    elif com[0]=='delete':
        try:
            q.remove(int(com[0]))
        except:
            pass
    elif com[0]=='deleteFirst':
        q.popleft()
    elif com[0]=='deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=1000000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0]=='insert':
        q.appendleft(int(com[1]))
    elif com[0]=='delete':
        try:
            q.remove(int(com[1]))
        except ValueError:
            pass
    elif com[0]=='deleteFirst':
        q.popleft()
    elif com[0]=='deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=1000000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0]=='insert':
        q.appendleft(int(com[1]))
    elif com[0]=='delete':
        try:
            q.remove(int(com[1]))
        except:
            pass
    elif com[0]=='deleteFirst':
        q.popleft()
    elif com[0]=='deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=1000000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.appendleft(int(com[1]))
    elif com[0] == 'delete':
        try:
            q.remove(int(com[1]))
        except:
            pass
    elif com[0] == 'deleteFirst':
        q.popleft()
    elif com[0] == 'deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque(maxlen=10000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.appendleft(int(com[1]))
    elif com[0] == 'delete':
        try:
            q.remove(int(com[1]))
        except:
            pass
    elif com[0] == 'deleteFirst':
        q.popleft()
    elif com[0] == 'deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque()

n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.appendleft(int(com[1]))
    elif com[0] == 'delete':
        try:
            q.remove(int(com[1]))
        except:
            pass
    elif com[0] == 'deleteFirst':
        q.popleft()
    elif com[0] == 'deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque()

n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.appendleft(int(com[1]))
    elif com[0] == 'delete':
        q.remove(int(com[1]))
    elif com[0] == 'deleteFirst':
        q.popleft()
    elif com[0] == 'deleteLast':
        q.pop()
print(' '.join(q))

Submission status: Runtime Error

Solution code:
import collections
q = collections.deque()
n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.appendleft(int(com[1]))
    elif com[0] == 'delete':
        q.remove(int(com[1]))
    elif com[0] == 'deleteFirst':
        q.popleft()
    elif com[0] == 'deleteLast':
        q.pop()

print(' '.join(q))

Submission status: Runtime Error

Solution code:
from collections import deque

def process_command(dll, commands):
    for cmd, num_str in commands:
        if cmd == 'insert':
            dll.appendleft(int(num_str))
        elif cmd == 'delete':
            temp = []
            result = dll.popleft()
            while result != int(num_str):
                temp.append(result)
                result = dll.popleft()
            dll.extendleft(temp)
        elif cmd == 'deleteFirst':
            dll.popleft()
        elif cmd == 'deleteLast':
            dll.pop()


if __name__ == '__main__':
    # ??????????????\???
    commands = []
    num = int(input())
    for i in range(num):
        commands.append([x for x in input().split(' ')])
    #commands.append(('insert', '5'))
    #commands.append(('insert', '2'))
    #commands.append(('insert', '3'))
    #commands.append(('insert', '1'))
    #commands.append(('delete', '3'))
    #commands.append(('insert', '6'))
    #commands.append(('delete', '5'))

    # ??????
    dll = deque()
    process_command(dll, commands)

    # ???????????????
    dll.reverse()
    print('{0}'.format(' '.join(map(str, dll))))

Submission status: Runtime Error

Solution code:
from collections import deque

def process_command(dll, commands):
    for cmd in commands:
        # print(cmd)
        if cmd.startswith('insert') or cmd.startswith('delete '):
            t = cmd.split(' ')
            cmd = t[0]
            num_str = t[1]
        if cmd == 'insert':
            dll.append(int(num_str))
        elif cmd == 'delete':
            temp = []
            result = dll.pop()
            while result != int(num_str):
                temp.append(result)
                result = dll.pop()
            temp = temp[::-1]
            dll.extend(temp)
        elif cmd == 'deleteFirst':
            dll.pop()
        elif cmd == 'deleteLast':
            dll.popleft()
        # print(dll)
        # print('=' * 64)


if __name__ == '__main__':
    # ??????????????\???
    commands = []
    num = int(input())
    for i in range(num):
        commands.append(input())
    #commands.append(('insert', '5'))
    #commands.append(('insert', '2'))
    #commands.append(('insert', '3'))
    #commands.append(('insert', '1'))
    #commands.append(('delete', '3'))
    #commands.append(('insert', '6'))
    #commands.append(('delete', '5'))

    # ??????
    dll = deque()
    process_command(dll, commands)

    # ???????????????
    dll.reverse()
    print('{0}'.format(' '.join(map(str, dll))))

Submission status: Runtime Error

Solution code:
from collections import deque

def process_command(dll, commands):
    for cmd in commands:
        # print(cmd)
        if cmd.startswith('insert') or cmd.startswith('delete '):
            t = cmd.split(' ')
            cmd = t[0]
            num_str = t[1]
        if cmd == 'insert':
            dll.appendleft(int(num_str))
        elif cmd == 'delete':
            temp = []
            result = dll.popleft()
            while result != int(num_str):
                temp.append(result)
                result = dll.popleft()
            temp = temp[::-1]
            dll.extendleft(temp)
        elif cmd == 'deleteFirst':
            dll.popleft()
        elif cmd == 'deleteLast':
            dll.pop()
        # print(dll)
        # print('=' * 64)


if __name__ == '__main__':
    # ??????????????\???
    commands = []
    num = int(input())
    for i in range(num):
        commands.append(input())

    # ??????
    dll = deque()
    process_command(dll, commands)

    # ???????????????
    # dll.reverse()
    print('{0}'.format(' '.join(map(str, dll))))

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    
    front = None
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            front = insert(front, { "next":None, "prev":None, "data":o[1] })
        elif opcode == "delete":
            front = delete(front, o[1])
        elif opcode == "deleteFirst":
            front = delete_first(front)
        elif opcode == "deleteLast":
            delete_last(front)
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, target):

    if front:
        front["prev"] = target
        target["next"] = front

    return target
    
def delete(front, target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"]
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front
    
def delete_last(front):
    last = front
    while front["next"]:
        last = last["next"]

    last["prev"]["next"] = None
    
def delete_first(front):
    front["next"]["prev"] = None
    return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    
    front = None
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            front = insert(front, { "next":None, "prev":None, "data":o[1] })
        elif opcode == "delete":
            front = delete(front, o[1])
        elif opcode == "deleteFirst":
            front = delete_first(front)
        elif opcode == "deleteLast":
            delete_last(front)
        #print(front["data"])
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, target):

    if front:
        front["prev"] = target
        target["next"] = front

    return target
    
def delete(front, target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"]
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front
    
def delete_last(front):
    last = front
    while last["next"]:
        last = last["next"]

    last["prev"]["next"] = None
    
def delete_first(front):
    front["next"]["prev"] = None
    return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    
    front = None
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            front = insert(front, { "next":None, "prev":None, "data":o[1] })
        elif opcode == "delete":
            front = delete(front, o[1])
        elif opcode == "deleteFirst":
            front = delete_first(front)
        elif opcode == "deleteLast":
            delete_last(front)
        #print(front["data"])
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, target):

    if front:
        front["prev"] = target
        target["next"] = front

    return target
    
def delete(front, target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"]
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front
    
def delete_last(front):
    last = front
    while last["next"]:
        last = last["next"]

    last["prev"]["next"] = None
    
def delete_first(front):
    front["next"]["prev"] = None
    return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    
    front = None
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            front = insert(front, { "next":None, "prev":None, "data":o[1] })
        elif opcode == "delete":
            front = delete(front, o[1])
        elif opcode == "deleteFirst":
            front = delete_first(front)
        elif opcode == "deleteLast":
            front = delete_last(front)
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    if not front:
        return []
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, target):

    if front:
        front["prev"] = target
        target["next"] = front

    return target
    
def delete(front, target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"]
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front
    
def delete_last(front):
    last = front
    while last["next"]:
        last = last["next"]

    if last == front:
        return None
    else:
        last["prev"]["next"] = None
        return front
    
def delete_first(front):
    front["next"]["prev"] = None
    return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
import gc
def dll_processor(operations):
    
    front = None
    end = None
    
    for o in operations:
        if o[0] == "insert":
            front, end = insert(front, end,{ "next":None, "prev":None, "data":o[1] })
        elif o[0] == "delete":
            front, end = delete(front, end, o[1])
        elif o[0] == "deleteFirst":
            front = delete_first(front)
        elif o[0] == "deleteLast":
            end = delete_last(end)
        gc.collect()
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    if not front:
        return []
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, end, target):

    if front:
        front["prev"] = target
        target["next"] = front
        return target, end
    else:
        return target, target
    
def delete(front, end,target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"], end
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front, delete_node["prev"]
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front, end
    
def delete_last(end):
    
    if not end["prev"]:
        return None
    else:
        end["prev"]["next"] = None
        return end["prev"]
    
def delete_first(front):
    
    if not front["next"]:
        return None
    else:
        front["next"]["prev"] = None
        return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()