You start your day, happily working with dictionaries…Life is good. >>> mydict = {‘key-a’: ‘value-a’, ‘key-b’: ‘value-b’} >>> mydict['key-a'] ‘value-a’ All of a sudden, storm clouds appear. Your dictionary variable accidentally gets assigned a list, and life is no longer good! >>> mydict = {‘key-a’: ‘value-a’, ‘key-b’: ‘value-b’} >>> mydict['key-a'] ‘value-a’ >>> mydict = [] [...]
Posts Tagged ‘Tuple’
What is a tuple?
Posted in Engineering, Interesting, Technique, tagged Python, Tuple on September 3, 2009 | Leave a Comment »
I get asked this from time to time, so for the fun of it, I’ll post this: Tuples are immutable lists in python (and other languages). Very lightweight, unchangable arrays. They are used for storing multiple values in one variable (usually a fixed number of values). x = (1, 2, 3, ‘abc’) x[0] -> 1 [...]