Estructuras de datos

Catalin Lungu lcatalin en siadv.com
Vie Sep 10 14:35:51 CEST 2004


Hola,
Muchas gracias por todo. Ahora lo tengo mucho mas claro. He hecho también la
clase ListDict que la presento a continuación a ver si le encontráis alguna
mejora o algún posible error.

class ListDict:
    def __init__(self):
        self.ldict = {"CLAVE ORDEN":[]}

    def GetClaves(self):
        return self.ldict["CLAVE ORDEN"]

    def GetValores(self):
        lst_ord = self.ldict["CLAVE ORDEN"]
        lst_val = []
        for clave in lst_ord:
            lst_val.append(self.ldict[clave])
        return lst_val

    def HasKey(self, clave):
        lst_ord = self.ldict["CLAVE ORDEN"]
        if clave in lst_ord:
            return True
        else:
            return False

    def GetValor(self, clave):
        return self.ldict[clave]

    def InsertValor(self, clave, valor, pos=-1):
        if clave != "CLAVE ORDEN":
            self.ldict[clave] = valor
            if pos == -1:
                self.ldict["CLAVE ORDEN"].append(clave)
            else:
                self.ldict["CLAVE ORDEN"].insert(pos, clave)
            return True
        return False

    def GetIndice(self, clave):
        try:
            pos = self.ldict["CLAVE ORDEN"].index(clave)
        except:
            pos = -1
        return pos

Para usarla:
import ListDict as ld

midict = ls.ListDict()

Como seria posible que al escribir directamente midict en el shell que me
devuelva midict.GetClaves().

Un saludo,
Catalin Lungu




Más información sobre la lista de distribución Python-es