Python Tuples vs Lists vs Dictionary
Fri, 26 Nov 2010There is some confusion between tuples and lists and dictionaries. In Python a Tuple vs List is still a bit confusing to me, however it goes something look this I see:
# A list is created with square brackets: []
myList = ['one', 'two', 3]
# You call a list item with the index value:
myList[0]
# You CAN modify a list
myList[0] = 'new'
# Tuples are created with parentheses: ()
myTuple = ('one', 2, 3)
# You call a list item with the index value:
myTuple[1]
# You CAN'T modify a tuple
Then we have another to add to the confusion called Dictionaries. A dictionary is just what it sounds like, it has a name and a definition. You can think of it like an associative array in other languages
# Dictionaries are made with squigglies: {}
myDictionary = {'key':'value', 'hew2':'value2'}
# Items are called by their key, or associative key:
myDictionary['key']
What do you use for what? I'm not totally certain, I guess.