''' Purpose: function exploration with list manipulations ''' def rotate( x ) : ''' Updates list x by moving the last element of list x (if any) to the beginning of list x (a circular shift) Returns None ''' pass # pop off the thing at the end # insert what you just popped at the beginning # For this homework, it's important to use/look at the list module on the # website for functions we can use on lists! def rotate_k_times( x, k ) : ''' Updates list x by performing k circular shifts Returns None ''' # basically use the above function k times # how do you do things... multiple times??? def common( x, y ) : ''' Returns a new list whose elements are those elements in x that are also in y. The function does not modify parameters x and y in any way. ''' # Use an accumulator [] # loop through everything in x # check if each element IN x is also IN y # if it is add it to the accumulator! pass if ( __name__ == '__main__' ): # __name__ is a built in python variable. import abet # it is set to __main__ if you are running # that module as a program # it is set to the name of the module # if it is being imported abet.test_rotate() abet.test_rotate_k_times() abet.test_common() # The whole point of this is to show you that if we do # if (__name__ == '__main__'): # if we're in the file we wanna run, (which means that we're running the program # that has __name__ set to __main__), then go ahead and # test it right here. So it's basically a way for you to have modules # and testers/testing code all in the same file. # It says: If we're in the program we wanna test, run these tests. ''' SCRATCH FILE ''' # AID HELP # stuff = [3,1,'alpha',True, 2.71] # print( stuff ) # stuff.pop() # print( stuff ) # # # list_name.pop() removes the last element in the list! When we just call .pop # # it will remove the last element. # # when we set it equal to a variable, what we just popped (removed) is stored in # # remember # remember = stuff.pop() # remember is the value we're popping now # # It is removed and stored in the variable remember # print( remember ) # print( stuff ) # print() # # misc = ['hi', 'yes','no', False, 712 ] # # 0 1 2 3 4 # # list_name.insert( index, what we want to insert ) # # This will insert what we want to insert at index position 2! # # It will be put before whatever is at index 2 currentl. # # We had the 2 at index 2 but we basically just put it in front of 'no' (index 2) # print( misc ) # misc.insert(2, 'love') # print( misc ) # Remember insert and pop for that hw!