Study Guide for Quiz 4
There will be a quiz on Wednesday (12 November 2008). The quiz will
be on lists. Unlike the other quizzes, you will be asked to
write code.
Here is a check list of operations that you should be familiar with
lists:
- Create a 1-D and 2-D list
- Traverse a 1-D and 2-D list
- Sum and average all the elements in a 1-D and 2-D list
- Compare two lists (1-D and 2-D) and determine if they have
exactly the same elements in the same order
- Determine if a 1-D list is sorted in ascending or descending
order
- Determine if a 1-D list is a palindromic
- Find the maximum and minimum in a 2-D list of numbers
- Find the second highest number in 1-D and 2-D list
- Add element by element two lists (1-D and 2-D) and produce
another list that has the sum
- Multiply element by element two (1-D) lists and add the
product (scalar product)
- Add either a row or column in a 2-D list
- Add the diagonal elements in a 2-D square list
- Merge two sorted 1-D lists and produce a third list
- Given two 2-D lists representing two matrices perform a matrix
multiplication
Here are some specific questions for the quiz. For each question write
a piece of code and run it to make sure it works.
- Write a function that takes as input a 1-D list and returns
an exact copy of that list.
- Write a function that takes as input a 2-D list and returns
an exact copy of that list.
- Write a function that compares two 1-D lists and returns True if
they have the same elements in the same order and False otherwise.
- Write a function that compares two 2-D lists and returns True if
they have the same elements in the same order and False otherwise.
- Create a 1-D list that has the powers of 2 from 20 to
210. You have to use a loop to generate this list. Enumerating
the elements of the list is not acceptable. The final list will look like
so:
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
- Create a 2-D list that has the numbers from 1 through 10, the square
of the number, and the cube of the number. You must use a loop to
generate this list. Enumerating the elements of the list is not
acceptable. The final list will look like so:
[ [ 1, 1, 1],
[ 2, 4, 8],
[ 3, 9, 27],
[ 4, 16, 64],
[ 5, 25, 125],
[ 6, 36, 216],
[ 7, 49, 343],
[ 8, 64, 512],
[ 9, 81, 729],
[10, 100, 1000]]
- Write function that will take as input a 1-D list and print
out the sum and the average of all the numbers.
- Write a function that will take as input a 2-D list and print
out the sum and the average of all the numbers.
- Write a function that will take as input a 2-D list and print
the sum of each row separately.
- Write a function that will take as input a 2-D list and print
the sum of each column separately. Assume that all the rows have
the same number of columns.
- Write a function that will take as input a 1-D list and return True
if all the elements are sorted in ascending order and False otherwise.
It will return True if all the elements are the same.
- Write a function that will take as input a 1-D list and return True
if the list is palindromic and False otherwise. You may not reverse
the list and compare. You will compare the first element with the last,
the second element with the second from the last element, and so on.