''' Support your understanding of lists built-in support ''' # get some lists print() s = "we are in it together" values = [ ] stuff = [ 'abc', 1112, 2.71, ] # lists can have multiple different values, multiple types digits = [ 3, 1, 4, 1, 5, 9, 2, 6 ] words = s.split() # s.split() --> split our strings on whitespace --> list of words # determine their sizes # built-in functions are never 'dotted' # you have a dot when the functions are behavioral functions when you have objects # objects have behavior # strings are objects in python --> they have certain behaviors for strings # behaviors include splitting a string on a character --> we use the split() function # some_string.split() vlen = len( values ) # so far we have 0 things in the list values slen = len( stuff ) # we have 3 things in stuff dlen = len( digits ) # we have 8 things in digits wlen = len( words ) # we have 5 things in 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() # determine the max and min of the homogeneous lists # never have a variable called max, min, or sum! These are function names in python!! dmax = max( digits ) # max( x ) where x is a list of strings and a list of numbers # gives you back the maximum value within x dmin = min( digits ) # min( x ): # gives you back the minimum value within x # lexicographical order: ordering by the value of each character in the alphabet # a is the minimum value and z is the max value # when max() and min() compares between strings, they compare EACH CHARACTER AT A TIME # 'we' vs 'are' # compares 'w' vs 'a' --> 'w' > 'a' in the lexicographical order # 'in' vs 'it' # compares 'i' vs 'i' --> they're equal --> move on # compares 'n' vs 't' --> 'n' < 't' --> so 'in' comes before 'it' wmax = max( words ) wmin = min( words ) print( "max of", digits, "=", dmax ) print( "min of", digits, "=", dmin ) print() print( "max of", words, "=", wmax ) print( "min of", words, "=", wmin ) print() s_max = max( stuff ) print( s_max ) # if your list has both numbers and strings, max() CANNOT compare between strings and numbers!! # only use max() and min() with lists that are purely numbers or purely strings