Last active
December 17, 2015 22:09
-
-
Save vrillusions/5679994 to your computer and use it in GitHub Desktop.
Example of a primitive queue in python
This file contains hidden or 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
#!/usr/bin/env python | |
# Very basic FILO queue in python | |
# | |
# BUG: get_item() has no ACK method so if the item that is getted fails it's | |
# gone | |
list = [] | |
def add_item(content): | |
"""Append to the end of the list.""" | |
global list | |
list.append(content) | |
def get_item (): | |
"""Get the first item (and thus the oldest) in list.""" | |
global list | |
return list.pop(0) | |
add_item(['this', 'array', 'is', 'one', 'item']) | |
print get_item() | |
add_item('item 1') | |
add_item('item 2') | |
print get_item() | |
add_item('item 3') | |
add_item('item 4') | |
print get_item() | |
add_item('item 5') | |
add_item('item 6') | |
add_item('item 7') | |
print get_item() | |
print get_item() | |
print list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment