>>> # Data structures contain any of the basic types or can >>> # contain data structures as well >>> >>> ## Lists (similar to arrays in other languages) >>> list = [23, 3.0, 'blah'] >>> print list >>> print list[0] >>> print list[1] >>> >>> # calculate the number of elements in the list with 'len(list)' >>> print len(list) >>> >>> # remove and return an element with the index passed to the function 'pop(index)' >>> list.pop(0) >>> print len(list) >>> >>> list = [] >>> list.append(0.0) >>> list.append(3.0) >>> print list >>> print list[0] >>> print list[1] >>> print len(list) >>> >>> # splitting strings into a list of tokens >>> stringValue = "some text to be split" >>> >>> # the line below splits stringValue into a list of tokens based on >>> # whitespace (i.e., Tab-delimted file formats) >>> tokens = stringValue.split() >>> print tokens >>> >>> stringValue = "different,text,to,be,split,by,commas" >>> >>> # the line below splits stringValue into a list of tokens based on >>> # commas (i.e., CSV file formats) >>> tokens = stringValue.split(',') >>> print tokens >>> >>> # recombining split text >>> tokens.pop(2) >>> tokens.pop(2) >>> print " ".join(tokens) >>> print ", ".join(tokens) # making a CSV line >>> print "\t".join(tokens) # making a tab-delimited line >>> >>> ## Dictionaries (aka associative arrays in other languages) >>> dictionary = dict() >>> dictionary['key1'] = "Some Value" >>> dictionary['key2'] = 3.0 >>> print dictionary >>> print dictionary['key1'] >>> print dictionary.keys() >>> print dictionary.has_key('key2') >>> dictionary = {'key2':3.0,'key1':'Some Value'} >>> print dictionary >>> print dictionary['key2'] |