what is the difference between the two kinds of brackets?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Oct 20 21:01:51 EDT 2007


On Sat, 20 Oct 2007 12:43:31 +0000, Steve Lamb wrote:

> The quick answer is that tuples can be indexes into directories
> while lists cannot.


A note on terminology: the things inside curly brackets {} are called 
dictionaries, or dicts, not directories. And the things you use to store 
data in dictionaries are called keys, not indexes:

# Lists have indexes:
L = ['x', 'y', 'z']
L[0] # returns the item in position 0

# Dicts have keys:
D = {'a': 'x', 2: 'y', 7.8: 'z'}
D['a'] # returns the item with key 'a'



-- 
Steven.



More information about the Python-list mailing list