Fall 2015 Final Study Guide (adopted from Sarah Diesburg's CS 1510 final exam study guide) Updated by Dr. Diesburg on 11/28/2015 Modified by Mark Jacobson as of 12/08/2015 (7:30 am) as of 12/10/2015 (8:50 pm) This final exam is cumulative but will focus on materials covered since the last exam. To practice for the exam, please study the notes, materials, and readings posted on the class webpage. You may also want to practice by writing code for and answering the following: Lists: What are they? How do you add items to a list (.append(), .insert()) How do you remove things from a list (.pop(), and .pop(index)) How do YOU search a list? (writing code that does this, not using native functions) Linear search and binary search. Dictionaries: What are they? How do you access an individual value based on its key? How do you change/set a key to a particular value? How do you get access to all of the keys of a dictionary? How do you get access to all of the values of a dictionary? Sample list programs: -------------------- Write a function called negate(myList) which takes in a list of numbers as a parameter and negates each value in the list. Since the function changes the list provided as a parameter it does not need to return anything. Write a function called negativeCopy(myList) which takes in a list of numbers as a parameter and returns a newly created list which is contains the negative values of the original list. For example, For example, negativeCopy([ 1, -2, 3.5, 4.2, ] ) would return [-1, 2, -3.5, -4.2] Write a function called addList(myList, addend) which takes in a list of numbers and a single addend as parameters. The function returns a newly created list which is each number in the original list plus the addend. For example, addList([1,2,3.5,4.2] , 3) would return [4, 5, 6.5, 7.2] Write a function called reverseList(myList) which takes in a list of items and returns a newly created list which is the original list in reverse. For example, reverseList([ 1, 2, 3.5, 4.2]) would return [4.2, 3.5, 2, 1] Write a function called removeItem(myList,item) which takes in a list and an item and returns a new list with each occurrence of the item removed from the original list. For example, removeItem([1, 2, "the", "test", 3, "is", "the", "best" ], "the") would return [1, 2, "test", 3, "is", "best" ] Write a function called sumOf(myList) which takes in a list of numbers as a parameter and returns the sum of all of the values in the list. Write a function called productOf(myList) which takes in a list of numbers as a parameter and returns the product of all of the values in the list. Write a function called count(myList,item) which takes in a list and an item and returns an integer representing how many times the item was in the original list. For example, count([1, 2, "the", "test", 3, "is", "the", "best" ], "the") would return 2, but count([1, 2, "the", "test", 3, "is", "the", "best" ], "Another") would return 0. (note, I am asking you to do the work here, not use native functionality). Write a function called mean(myList) which takes in a list of numbers and returns a decimal value which is the mean (the statistical "average") of the numbers in the list. Write a function called median(myList) which takes in a list of numbers and returns the value which is the arithmetic median of that list (the "middle" value when the list is sorted into order) Write a function called mode(myList) which takes in a list of numbers and returns the value which occurs in the list the most times. Sample dictionary programs: -------------------------- Write a function called keyCount(myDictionary) which takes in a dictionary as a parameter and returns an integer representing the number of keys in the dictionary Write a function called valueCount(myDictionary) which takes in a dictionary as a parameter and returns an integer representing the number of UNIQUE values in the dictionary. Write a function called valueCount(myDictionary,value) which takes in a dictionary as a parameter and returns an integer representing how many times THAT value is a value in the dictionary. Write a function called setValue(myDictionary, key, newValue) which takes in a dictionary as a parameter, locates the key in the dictionary and replaces the existing value with the newValue parameter. Write a function called mostCommon(myString) which takes in a string and returns the most common letter in that string. Write a function called letterCounts(mystring) which takes in a string and returns a dictionary of letter counts in that string. ---------------------------------------------------------------------------- This list is not exhaustive. Please do not forget about strings, loops, conditional statements, and other programming concepts you learned earlier in the class. ----------------------------------------------------------------------------