''' Purpose: better experience functional development ''' # helpful named strings # If you write functions in the same module, you can call those functions defined in the # same file in other functions without importing the module and doing module.function_name() # We don't have to import quad in quad.py! We're already in quad! # So if you want to use the lower( strings ) function in the same # module (quad.py like in canoncial()) just call lower( strings ) no need to do # quad.lower( strings ) in the same file! PUNCTUATION = '''!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~''' WHITE_SPACE = ' \t\n\r\v\f' EXTRANEOUS = PUNCTUATION + WHITE_SPACE def lower( strings ) : ''' Returns a new list whose elements are lower case versions of those in strings ''' result = [] # accumulator - build up a list of the lowercase strings # You can call .lower() on a single string but a list doesn't have a lower function! for s in strings: # Go through each string in list of strings lowered_s = s.lower() # Get the lowercase version result.append( lowered_s ) # Add the lowercase version to our result return result def unique( strings ) : ''' Returns a new version of strings without any duplicate values ''' pass def strip( strings ) : ''' Returns a new version of strings where the corresponding elements have leading and trailing extraneous characters (punctuation or whitespace) removed ''' pass def canonical( strings ) : ''' Returns a new version of strings without duplicate values where the corresponding elements have leading and trailing extraneous characters (punctuation or whitespace) removed and are in lowercase ''' # Do three things: remove extraneous characters, lowercase everything, and have # duplicate values removed ^ look at the above functions # Order matters! What order do we want to do these three things? # Call the functions above on the list of strings one by one! # Make all the strings lowercase! list_lowercase_strings = lower( strings ) # Make all the lowercase strings stripped! list_stripped_lowercase_strings = strip( list_lowercase_strings ) # Get rid of duplicates in the lowercase stripped versions! Remove duplicates last! list_stripped_lowercase_unique_strings = unique( list_stripped_lowercase_strings ) return list_stripped_lowercase_unique_strings