class Queue(object): def __init__(self): "Initializes 1 attribute: a list to keep track of the queue's elements" self.qlist = [] def insert(self, element): "Adds an element to the attribute list using append" self.qlist.append(element) def remove(self): "Removes an element from the attribute list" # Check if the list is empty; if so then raise a ValueError if self.qlist == []: raise ValueError() else: # Otherwise we want to remove the first element from the list # and return that to the user. element = self.qlist[0] self.qlist.remove(element) return element # Could also do this in 1 line: # return self.qlist.pop(0)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question