/* */

Thursday, 24 March 2011

Advantages of Dictionaries over Lists

x = []
x = [42] = 'Foobar'
-error
x = {}
x[42] = 'Foobar'
x
{42 : 'Foobar'}
When we try to assign a value to position 42 in a list it returns an error because items 0-41 dont exist. Because a dictionary relies on mapping rather than sequencing, the key can be created.    

No comments:

Post a Comment