Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- import bisect
- class ElementosOrdenados(collections.Sequence):
- def __init__(self, inicial = None):
- self._elementos = sorted(inicial) if inicial is not None else []
- def __getitem__(self, indice):
- return self._elementos[indice]
- def __len__(self):
- return len(self._elementos)
- def agregar(self, elemento):
- bisect.insort(self._elementos, elemento)
- elementos = ElementosOrdenados([2, 3, 5])
- print(list(elementos))
- print(elementos[0])
- print(elementos[-1])
- elementos.agregar(-2)
- print(list(elementos))
- print(elementos[1:4])
- print(5 in elementos)
- print(len(elementos))
- for elmt in elementos:
- print(elmt, ' ', end='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement