Wish Lists

Today we are going to review Python lists.  Begin by reviewing the assignments we have already completed with lists, as well as the tutorial.


Now, create one large Python program in IDLE that includes all of the following exercises.  Name the file lastname-firstname-ListReview.py .

List Basics:

  1. Create a list named wordList that contains the following words: “washington”, “lee”, “generals”, “arlington”, “virginia”.
  2. Print out the first element in wordList.
  3. Print out the length of the list by using len(wordList).
  4. Print out the last element in wordList by using wordList[len(wordList)-1].
  5. Print out the word “generals” in the list by accessing the appropriate element.

Lists with loops:

  1. Create a second list named numList with the following numbers 3, 1, 7, 6, 4, 1, 1, 5, 4, 7, 9, 0, 9, 7, 7, 43, 2, 6, 87, 67, 4, 2, 532.
  2. Print out the last element in numList using len(numList)-1.
  3. Print out the middle element in numList using len(numList) // 2 (the double division sign is intentional–it automatically rounds down) to locate the middle element index.
  4. Write a loop that goes from 0 up through len(numList)-1 that prints out ALL the elements in numList.
  5. Write a loop that goes from len(numList)-1 down through 0 and prints numList in reverse order
  6. Write a loop that prints out all the numbers in numList that are greater than 10.
  7. Write a loop that prints out all the numbers in numList that are even (HINT: if numList[x]%2 == 0)
  8. Use the sort() method to sort the list (info on sort at this link).  Then use a loop to print all the elements in the list to make sure it is sorted.

Adding and removing elements:

  1. Create an empty list [] named myList.
  2. Add the following words to myList by using myList.append( WORD ) for each of the words:
    • “The”
    • “quick”
    • “brown”
    • “fox”
    • “jumps”
    • “over”
    • “the”
    • “lazy”
    • “dog”
  3. Use a loop to print the elements of myList to see if all the words were added.
  4. Delete the word “brown” from the list by using del myList[ LOCATION ].
  5. Now delete the word “over”.
  6. Use a loop to again print the elements of myList to see if the correct words were deleted.

Once the program is completed and produced the correct output, please create a Microsoft Word document with the name lastname-firstname-ListReview.docx with your name, the program description, the program code, and the output pasted into the document.  Format the document in the same manner as the programs that we’ve completed the last couple of days.  DO NOT print this file.  Instead, please submit the file using this submission link.