Definition of class SimpleDictionary. : Your Dictionary : Collections PYTHON TUTORIALS


PYTHON TUTORIALS » Collections » Your Dictionary »

 

Definition of class SimpleDictionary.


class SimpleDictionary:
   def __getitem__self, key ):
      return self.__dict__key ]

   def __setitem__self, key, value ):
      self.__dict__key = value

   def __delitem__self, key ):
      del self.__dict__key ]      

   def __str__self ):
      return strself.__dict__ )

   def keysself ):
      return self.__dict__.keys()

   def valuesself ):
      return self.__dict__.values()

   def itemsself ):
      return self.__dict__.items()
   

simple = SimpleDictionary()
print "The empty dictionary:", simple

simple"one"
simple"two"
simple"three"
print "The dictionary after adding values:", simple

del simple
print "The dictionary after removing a value:", simple

print "Dictionary keys:", simple.keys()
print "Dictionary values:", simple.values()
print "Dictionary items:", simple.items()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Collections
» Your Dictionary