tutorial4 dict



In [1]:
studentIds = {'knuth': 42.0, 'turing': 56.0, 'nash': 92.0 }

In [2]:
studentIds['turing']


Out[2]:
56.0

In [3]:
studentIds['nash'] = 'ninety-two'

In [4]:
studentIds


Out[4]:
{'knuth': 42.0, 'nash': 'ninety-two', 'turing': 56.0}

In [5]:
del studentIds['knuth']

In [6]:
studentIds


Out[6]:
{'nash': 'ninety-two', 'turing': 56.0}

In [7]:
studentIds['knuth'] = [42.0,'forty-two']

In [8]:
studentIds


Out[8]:
{'knuth': [42.0, 'forty-two'], 'nash': 'ninety-two', 'turing': 56.0}

In [9]:
studentIds.keys()


Out[9]:
['knuth', 'nash', 'turing']

In [10]:
studentIds.values()


Out[10]:
[[42.0, 'forty-two'], 'ninety-two', 56.0]

In [11]:
studentIds.items()


Out[11]:
[('knuth', [42.0, 'forty-two']), ('nash', 'ninety-two'), ('turing', 56.0)]

In [14]:
help(dict.items)


Help on method_descriptor:

items(...)
    D.items() -> list of D's (key, value) pairs, as 2-tuples

In [16]:
dir(dict)


Out[16]:
['__class__',
 '__cmp__',
 '__contains__',
 '__delattr__',
 '__delitem__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__gt__',
 '__hash__',
 '__init__',
 '__iter__',
 '__le__',
 '__len__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__setitem__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'clear',
 'copy',
 'fromkeys',
 'get',
 'has_key',
 'items',
 'iteritems',
 'iterkeys',
 'itervalues',
 'keys',
 'pop',
 'popitem',
 'setdefault',
 'update',
 'values',
 'viewitems',
 'viewkeys',
 'viewvalues']

In [ ]: