''' Support your understanding of lists built-in support ''' # get some lists # lists are NOT functions, they are a data type that holds multiple values # functions get parentheses, lists and sequences get brackets # lists and string indices/slices work the same way, both start indexing at 0 # brackets are nowhere in functions, brackets are exclusive to sequences print() s = "We Are In It Together" values = [ ] # empty list # if you are going to build a list... maybe even in a for loop... we'll definitely never do that (this is a lie) # empty lists are incredibly useful in programming, we'll build lists using accumulation # when accumulating a list, you start out with an empty list [] # when accumulating a total, start with 0 # stuff = [ 'abc', 1112, 2.71, ] # lists can hold multiple different data types in python digits = [ 3, 1, 4, 1, 5, 9, 2, 6 ] # we can use operators in lists, but we avoid it in 1112, as python is special in this regard # when people use operators on tests, code blows up... no one likes that words = s.split() # words is a list produced from splitting s on whitespace # we can add on to lists after making them with the append() method function # determine their sizes vlen = len( values ) # calculates the length of a sequence - for a list, returns the number of elements slen = len( stuff ) dlen = len( digits ) wlen = len( words ) # report their sizes print( "size of", values, "=", vlen ) print() print( "size of", stuff, "=", slen ) print() print( "size of", digits, "=", dlen ) print() print( "size of", words, "=", wlen ) print() input( "enter when ready" ) # you're not allowed to do this until you have a CS degree # this is sneaky and makes you hit enter before displaying the rest. this was done so we could talk about # multiple functions in one program print() # determine the max and min of the homogeneous lists dmax = max( digits ) dmin = min( digits ) wmax = max( words ) wmin = min( words ) # min() and max() only work on homogenous strings, everything needs to be same data type print( "max of", digits, "=", dmax ) print( "min of", digits, "=", dmin ) print() print( "max of", words, "=", wmax ) print( "min of", words, "=", wmin ) # min and max operate on strings by lexiographical (basically alphabetical) order - capitals come before lowercase # these are based on Unicode, so don't get mad at us please # GOTCHA: max/min does not look at string length!! print()