Fhernd icon

contenedor_personalizado.py

Fhernd | PRO | 01/07/19 12:49:19 PM UTC | 0 ⭐ | 2026 👁️ | Never ⏰ | []
Python |

700 B

|

None

|

0 👍

/

0 👎

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='')

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎