Tuesday, October 27, 2015
python dictionary
http://learnpythonthehardway.org/book/ex39.html
http://www.tutorialspoint.com/python/python_dictionary.htm
http://stackoverflow.com/questions/10380992/get-python-dictionary-from-string-containing-key-value-pairs
You can use numbers to "index" into a list, meaning you can use numbers to find out what's in lists. You should know this about lists by now, but make sure you understand that you can only use numbers to get items out of a list.
What a dict does is let you use anything, not just numbers. Yes, a dict associates one thing to another, no matter what it is. Take a look:
>>> stuff = {'name': 'Zed', 'age': 39, 'height': 6 * 12 + 2}
>>> print stuff['name']
Zed
>>> print stuff['age']
39
>>> print stuff['height']
74
>>> stuff['city'] = "San Francisco"
>>> print stuff['city']
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment