Mapytex/generic.py

64 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# encoding: utf-8
class Stack(object):
2013-08-07 23:12:11 +00:00
"""Docstring for Stack """
2013-08-07 23:12:11 +00:00
def __init__(self):
"""@todo: to be defined1 """
self.items = []
2013-08-07 23:12:11 +00:00
def pushFromList(self, list):
"""Push the list in the stack
2013-07-18 17:43:36 +00:00
2013-08-07 23:12:11 +00:00
:param list: a list
"""
for i in list[::-1]:
self.push(i)
2013-07-18 17:43:36 +00:00
2013-08-07 23:12:11 +00:00
def isEmpty(self):
""" Says if the stack is empty
:returns: @todo
2013-08-07 23:12:11 +00:00
"""
return self.items == []
2013-08-07 23:12:11 +00:00
def push(self, item):
"""Push an item in the stack
2013-08-07 23:12:11 +00:00
:param item: @todo
:returns: @todo
2013-08-07 23:12:11 +00:00
"""
self.items.append(item)
2013-08-07 23:12:11 +00:00
def pop(self):
"""Getting the last item and remove it
:returns: last item
2013-08-07 23:12:11 +00:00
"""
return self.items.pop()
2013-08-07 23:12:11 +00:00
def peek(self, posi = 0):
"""Getting the last item
2013-07-18 17:43:36 +00:00
:param posi: which item to peek 0 (last) 1 (the onebefore the last)...
2013-08-07 23:12:11 +00:00
:returns: the item
2013-08-07 23:12:11 +00:00
"""
return self.items[-1 - posi]
2013-08-07 23:12:11 +00:00
def __len__(self):
return len(self.items)
2013-08-07 23:12:11 +00:00
def __str__(self):
return str(self.items) + " -> "
2013-08-07 23:12:11 +00:00
def __add__(self, addList):
return self.items + addList
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del